How to center flushed-right column text in Kable?Aligning Columns with knitr kable functionRMarkdown kable vertically align cellsHow to wrap text in LaTeX tables?How to sort a dataframe by multiple column(s)How to join (merge) data frames (inner, outer, left, right)General guide for creating publication quality tables using R, Sweave, and LaTeXKnitr creates black box blocking name of first column when creating a tableHow can I subscript names in a table from kable()?R Kable: Rotating Text in Column GroupingHow to remove/hide column names in kable?Replace column names in kable/R markdownR kableExtra latex: Add linebreaks to rotated header row

Exploiting the delay when a festival ticket is scanned

How to prevent a single-element caster from being useless against immune foes?

Security measures that could plausibly last 150+ years?

Is it bad style if the personal first person narrator of a story dies during said story?

Why tantalum for the Hayabusa bullets?

Road bike front wheel question

Should students have access to past exams or an exam bank?

Solve equation using Mathematica

"Valet parking " or "parking valet"

What is a Trio Word™?

Why didn't Stark and Nebula use jump points with their ship to go back to Earth?

What are the closest international airports in different countries?

Is it possible for a particle to decay via gravity?

How did astronauts using rovers tell direction without compasses on the Moon?

How to have poached eggs in "sphere form"?

Does Ubuntu reduce battery life?

Is it unprofessional to mention your cover letter and resume are best viewed in Chrome?

Why doesn't the Gottesman-Knill theorem render quantum computing almost useless?

Dynamic Icon loading in LWC doesn't work

When encrypting twice with two separate keys, can a single key decrypt both steps?

Scam? Checks via Email

Embedded C - Most elegant way to insert a delay

Just how much information should you share with a former client?

My employer is refusing to give me the pay that was advertised after an internal job move



How to center flushed-right column text in Kable?


Aligning Columns with knitr kable functionRMarkdown kable vertically align cellsHow to wrap text in LaTeX tables?How to sort a dataframe by multiple column(s)How to join (merge) data frames (inner, outer, left, right)General guide for creating publication quality tables using R, Sweave, and LaTeXKnitr creates black box blocking name of first column when creating a tableHow can I subscript names in a table from kable()?R Kable: Rotating Text in Column GroupingHow to remove/hide column names in kable?Replace column names in kable/R markdownR kableExtra latex: Add linebreaks to rotated header row






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I am having a dataframe with both character and numeric columns. I am trying to center the character column (which is done) and (I don't know how to) center flushed-right numeric column. Further, both column names are centered:
desired look



Some relevant posts (this and this), but I couldn't incorporate the techniques (if relevant) to my code.



The following code produces the table below:



df <- data.frame(name = c("a", "bb", "ccc"), number = c(10, 193048, 200))

kable(df, format="latex", align = c("c", "r")) %>%
kable_styling(full_width = TRUE) %>%
row_spec(0, align = "c")


current look



I understand that I can use LaTeX code to produce a single user-customised table. But I need the example to be reproducible in Rmd (imagine I have lots of df) and therefore need to specify within kable().



Should I modify the LaTeX table environment (i.e. begintabu to linewidth >centeringX>centeringX) and if so how in R, or use something like multirow to customise the second column??










share|improve this question


























  • My answer here might be relevant. It doesn't use Latex directly, though.

    – lmo
    Mar 27 at 0:28











  • Thank you @Imo, I may have missed it, but I didn't see any info on center and right alignment for the column.

    – Jane
    Mar 27 at 0:36











  • This combo does not appear to be possible directly in kable. You may be able to fake it using sprintf with the proper formatting, ie adding enough blank spaces to get it to look good enough. Take a look at the examples in the manual page if you want to give that a try. Alternatively, there are a number of alternative table functions, xtable, and something in hmisc, also the package tables. Good luck.

    – lmo
    Mar 27 at 0:49






  • 1





    Will give these options a try!

    – Jane
    Mar 27 at 20:23

















1















I am having a dataframe with both character and numeric columns. I am trying to center the character column (which is done) and (I don't know how to) center flushed-right numeric column. Further, both column names are centered:
desired look



Some relevant posts (this and this), but I couldn't incorporate the techniques (if relevant) to my code.



The following code produces the table below:



df <- data.frame(name = c("a", "bb", "ccc"), number = c(10, 193048, 200))

kable(df, format="latex", align = c("c", "r")) %>%
kable_styling(full_width = TRUE) %>%
row_spec(0, align = "c")


current look



I understand that I can use LaTeX code to produce a single user-customised table. But I need the example to be reproducible in Rmd (imagine I have lots of df) and therefore need to specify within kable().



Should I modify the LaTeX table environment (i.e. begintabu to linewidth >centeringX>centeringX) and if so how in R, or use something like multirow to customise the second column??










share|improve this question


























  • My answer here might be relevant. It doesn't use Latex directly, though.

    – lmo
    Mar 27 at 0:28











  • Thank you @Imo, I may have missed it, but I didn't see any info on center and right alignment for the column.

    – Jane
    Mar 27 at 0:36











  • This combo does not appear to be possible directly in kable. You may be able to fake it using sprintf with the proper formatting, ie adding enough blank spaces to get it to look good enough. Take a look at the examples in the manual page if you want to give that a try. Alternatively, there are a number of alternative table functions, xtable, and something in hmisc, also the package tables. Good luck.

    – lmo
    Mar 27 at 0:49






  • 1





    Will give these options a try!

    – Jane
    Mar 27 at 20:23













1












1








1








I am having a dataframe with both character and numeric columns. I am trying to center the character column (which is done) and (I don't know how to) center flushed-right numeric column. Further, both column names are centered:
desired look



Some relevant posts (this and this), but I couldn't incorporate the techniques (if relevant) to my code.



The following code produces the table below:



df <- data.frame(name = c("a", "bb", "ccc"), number = c(10, 193048, 200))

kable(df, format="latex", align = c("c", "r")) %>%
kable_styling(full_width = TRUE) %>%
row_spec(0, align = "c")


current look



I understand that I can use LaTeX code to produce a single user-customised table. But I need the example to be reproducible in Rmd (imagine I have lots of df) and therefore need to specify within kable().



Should I modify the LaTeX table environment (i.e. begintabu to linewidth >centeringX>centeringX) and if so how in R, or use something like multirow to customise the second column??










share|improve this question
















I am having a dataframe with both character and numeric columns. I am trying to center the character column (which is done) and (I don't know how to) center flushed-right numeric column. Further, both column names are centered:
desired look



Some relevant posts (this and this), but I couldn't incorporate the techniques (if relevant) to my code.



The following code produces the table below:



df <- data.frame(name = c("a", "bb", "ccc"), number = c(10, 193048, 200))

kable(df, format="latex", align = c("c", "r")) %>%
kable_styling(full_width = TRUE) %>%
row_spec(0, align = "c")


current look



I understand that I can use LaTeX code to produce a single user-customised table. But I need the example to be reproducible in Rmd (imagine I have lots of df) and therefore need to specify within kable().



Should I modify the LaTeX table environment (i.e. begintabu to linewidth >centeringX>centeringX) and if so how in R, or use something like multirow to customise the second column??







r latex r-markdown kable






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 21:30







Jane

















asked Mar 26 at 21:25









JaneJane

13510 bronze badges




13510 bronze badges















  • My answer here might be relevant. It doesn't use Latex directly, though.

    – lmo
    Mar 27 at 0:28











  • Thank you @Imo, I may have missed it, but I didn't see any info on center and right alignment for the column.

    – Jane
    Mar 27 at 0:36











  • This combo does not appear to be possible directly in kable. You may be able to fake it using sprintf with the proper formatting, ie adding enough blank spaces to get it to look good enough. Take a look at the examples in the manual page if you want to give that a try. Alternatively, there are a number of alternative table functions, xtable, and something in hmisc, also the package tables. Good luck.

    – lmo
    Mar 27 at 0:49






  • 1





    Will give these options a try!

    – Jane
    Mar 27 at 20:23

















  • My answer here might be relevant. It doesn't use Latex directly, though.

    – lmo
    Mar 27 at 0:28











  • Thank you @Imo, I may have missed it, but I didn't see any info on center and right alignment for the column.

    – Jane
    Mar 27 at 0:36











  • This combo does not appear to be possible directly in kable. You may be able to fake it using sprintf with the proper formatting, ie adding enough blank spaces to get it to look good enough. Take a look at the examples in the manual page if you want to give that a try. Alternatively, there are a number of alternative table functions, xtable, and something in hmisc, also the package tables. Good luck.

    – lmo
    Mar 27 at 0:49






  • 1





    Will give these options a try!

    – Jane
    Mar 27 at 20:23
















My answer here might be relevant. It doesn't use Latex directly, though.

– lmo
Mar 27 at 0:28





My answer here might be relevant. It doesn't use Latex directly, though.

– lmo
Mar 27 at 0:28













Thank you @Imo, I may have missed it, but I didn't see any info on center and right alignment for the column.

– Jane
Mar 27 at 0:36





Thank you @Imo, I may have missed it, but I didn't see any info on center and right alignment for the column.

– Jane
Mar 27 at 0:36













This combo does not appear to be possible directly in kable. You may be able to fake it using sprintf with the proper formatting, ie adding enough blank spaces to get it to look good enough. Take a look at the examples in the manual page if you want to give that a try. Alternatively, there are a number of alternative table functions, xtable, and something in hmisc, also the package tables. Good luck.

– lmo
Mar 27 at 0:49





This combo does not appear to be possible directly in kable. You may be able to fake it using sprintf with the proper formatting, ie adding enough blank spaces to get it to look good enough. Take a look at the examples in the manual page if you want to give that a try. Alternatively, there are a number of alternative table functions, xtable, and something in hmisc, also the package tables. Good luck.

– lmo
Mar 27 at 0:49




1




1





Will give these options a try!

– Jane
Mar 27 at 20:23





Will give these options a try!

– Jane
Mar 27 at 20:23












1 Answer
1






active

oldest

votes


















0














Thanks to @Fran from this post, answer below:



df <- data.frame(name = c("a", "bb", "ccc"), number = c(10, 193048, 200))

kable(df,"latex", align="cr", booktabs = T, linesep = "") %>%
kable_styling() %>%
column_spec(1, width = "3em") %>%
column_spec(2, width = "3em")






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55366429%2fhow-to-center-flushed-right-column-text-in-kable%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Thanks to @Fran from this post, answer below:



    df <- data.frame(name = c("a", "bb", "ccc"), number = c(10, 193048, 200))

    kable(df,"latex", align="cr", booktabs = T, linesep = "") %>%
    kable_styling() %>%
    column_spec(1, width = "3em") %>%
    column_spec(2, width = "3em")






    share|improve this answer





























      0














      Thanks to @Fran from this post, answer below:



      df <- data.frame(name = c("a", "bb", "ccc"), number = c(10, 193048, 200))

      kable(df,"latex", align="cr", booktabs = T, linesep = "") %>%
      kable_styling() %>%
      column_spec(1, width = "3em") %>%
      column_spec(2, width = "3em")






      share|improve this answer



























        0












        0








        0







        Thanks to @Fran from this post, answer below:



        df <- data.frame(name = c("a", "bb", "ccc"), number = c(10, 193048, 200))

        kable(df,"latex", align="cr", booktabs = T, linesep = "") %>%
        kable_styling() %>%
        column_spec(1, width = "3em") %>%
        column_spec(2, width = "3em")






        share|improve this answer













        Thanks to @Fran from this post, answer below:



        df <- data.frame(name = c("a", "bb", "ccc"), number = c(10, 193048, 200))

        kable(df,"latex", align="cr", booktabs = T, linesep = "") %>%
        kable_styling() %>%
        column_spec(1, width = "3em") %>%
        column_spec(2, width = "3em")







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 29 at 22:41









        JaneJane

        13510 bronze badges




        13510 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55366429%2fhow-to-center-flushed-right-column-text-in-kable%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현