rstudio / blogdown

Create Blogs and Websites with R Markdown
https://pkgs.rstudio.com/blogdown/
1.73k stars 334 forks source link

Format table in Rmarkdown #428

Closed TrungLeVn closed 4 years ago

TrungLeVn commented 4 years ago

Hi, I am trying to add a table to my post to the Hugo Academic themes using Rmarkdown with the kableExtra package in an R chunk code. However, it seems that I can not customize the styling options to my table such as to position the table to the center of the page or to use the "basic" format in the bootstrap options (by default, the table appears with strips of alternative colors in each row).

Here is the reproducible code:

library(kableExtra)
library(knitr)
library(dplyr)
options(knitr.kable.NA = '')
options(kableExtra.html.bsTable = TRUE)
dt = mtcars[1:10,1:3]
kable(dt,format = "html") %>% kable_styling(position = "right",bootstrap_options = "basic")
jemus42 commented 4 years ago

Hugo Academic doesn't seem include bootstrap (I only checked by quickly cmd+F'ing through the source of https://themes.gohugo.io/theme/academic/), so my guess is that that's why bootstrap options don't work, as kable only adds the appropriate CSS classes to the table output, but doesn't forcibly include bootstrap (which would be a rather huge dependency, purely for some table styling)

You would have to manually add table-related CSS to your theme I think.