Right-align text column in a table

426 views
Skip to first unread message

Christopher Bratt

unread,
Apr 23, 2019, 10:25:00 AM4/23/19
to knitr
Is there any way to right-align a text column in a table, either with the kable function in knitr, or with kableExtra?
(I have browsed and googled for an answer, but with no success.)

Christopher Bratt

Rlastra .

unread,
Apr 23, 2019, 10:33:01 AM4/23/19
to Christopher Bratt, knitr
With Kable you can do a lot of visual things. Here in my example of piece of code you can se how it works:

kable(data, "html", format.args = list(decimal.mark = '.', big.mark = ","), linesep = "", align = "c", booktabs = T,digits = c(0,0,0,0,2))

Check the "align" function....

--
You received this message because you are subscribed to the Google Groups "knitr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knitr+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christopher Bratt

unread,
Apr 23, 2019, 10:54:53 AM4/23/19
to knitr
Thanks.

I believe this is for aligning the whole table (centered on the page)? I need to get down to a single column and align text within that single column  (and not manipulate any of the other columns).
 

On Tuesday, 23 April 2019 16:33:01 UTC+2, Rlastra . wrote:
With Kable you can do a lot of visual things. Here in my example of piece of code you can se how it works:

kable(data, "html", format.args = list(decimal.mark = '.', big.mark = ","), linesep = "", align = "c", booktabs = T,digits = c(0,0,0,0,2))

Check the "align" function....

On Tue, Apr 23, 2019 at 9:25 AM Christopher Bratt <christop...@gmail.com> wrote:
Is there any way to right-align a text column in a table, either with the kable function in knitr, or with kableExtra?
(I have browsed and googled for an answer, but with no success.)

Christopher Bratt

--
You received this message because you are subscribed to the Google Groups "knitr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kn...@googlegroups.com.

Rlastra .

unread,
Apr 23, 2019, 11:53:52 AM4/23/19
to Christopher Bratt, knitr
Youre right.

In that case use this:

row_spec(7:7, bold = T, color = "#000000", background = "red")

You can specify the hole format, and a specific colum, row or value.

To unsubscribe from this group and stop receiving emails from it, send an email to knitr+un...@googlegroups.com.

Rlastra .

unread,
Apr 23, 2019, 11:54:20 AM4/23/19
to Christopher Bratt, knitr
row_spec or col_spec, i forgot that

Christopher Bratt

unread,
Apr 24, 2019, 8:11:00 AM4/24/19
to knitr
Thanks, but I don't think col_spec includes the option to align text. 

Anyway, I have decided to use a different approach. Thanks for your effort!
Reply all
Reply to author
Forward
0 new messages