Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blogdown kable tables formatting (ugly)

kable(head(mtcars) %>%
  kable_styling(bootstrap_options = c("striped", "hover"))

A normal R Markdown document, utilizing a kable table (see above), is quite striking and looks like this:

kableExtra default

However, when I use the same code chunk in blogdown, the kable table is printed in a more minimalist fashion, which I don't really want. It's just hard to read:

kable blogdown

How do I get blogdown to maintain the properties of a normal kable table? I have updated all my packages via update.packages(ask = FALSE, checkBuilt = TRUE) and tinytex::tlmgr_update().

like image 393
Display name Avatar asked Mar 27 '19 18:03

Display name


Video Answer


2 Answers

You can also choose to ask kableExtra to load the bootstrap css for tables for you.

options(kableExtra.html.bsTable = TRUE)

This option is off by default because css might have conflicts between each other. However, in this case, since you have a blank table, which means that there is no table css defined in the HUGO theme selected, it should be fine.

like image 152
Hao Avatar answered Sep 29 '22 22:09

Hao


The appearances of the tables are controlled by the Hugo theme of your blogdown site. If the table styles are missing, you won't get those pretty tables.

Try adding the following CSS code in the CSS file of your blogdown sites.

table {
   margin: auto; 
   border-top: 1px solid #666; 
   border-bottom: 1px solid #666; 
}
table thead th { border-bottom: 1px solid #ddd; }
th, td { padding: 5px; }
tr:nth-child(even) { background: #eee; }

You can read more from the blogdown manual to learn how to custom your blogdown site.

like image 39
TC Zhang Avatar answered Sep 30 '22 00:09

TC Zhang