xaringan: kableExtra::kable_styling() and wider tables
Asked Answered
B

1

7

I am using xaringan to create an html presentation, which includes some tables generated using kable(). Unfortunately, these tables are quite narrow, so I'd like to use the full_width option in kable_styling. Moreover, I'd like to turn off the striped design. An example:

library(kableExtra)

head(iris) %>% 
knitr::kable('html') %>%
kableExtra::kable_styling(full_width = TRUE, bootstrap_options = "basic")

However, it looks like the kable_styling() options are ignored by xaringan. Is it possible to make these happen, or otherwise to modify the style of kable tables when using xaringan?

Bonar answered 23/3, 2019 at 22:55 Comment(0)
L
8

Try to add the following code before your kable table.

```{css, echo=F}
    /* Table width = 100% max-width */

    .remark-slide table{
        width: 100%;
    }

    /* Change the background color to white for shaded rows (even rows) */

    .remark-slide thead, .remark-slide tr:nth-child(2n) {
        background-color: white;
    }
```

If you would like to make a change to only one table, you may need to put the table in a container and modify the above code.

Let me know if it works.

Lutestring answered 1/4, 2019 at 22:21 Comment(4)
Hi Fei, do you maybe also have a suggestion to make the footnote from a threepart table , or a regular kable white (I am not a css wizz)? Thanks!Augustus
Hi Martine, did you try .tfoot .td { background-color: white}?Lutestring
Hu Fei, thanks for the suggestion. I did not untill now :). i pasted it in the css chunk. Unfortunately it did not affect the tables.Augustus
Hi Martine, you may open the html file in a browser and right click the table area and choose Inspect. There you should be able to find the right css selector. If it still doesn't work, you may post the link to the file so that I can check codes in the file.Lutestring

© 2022 - 2024 — McMap. All rights reserved.