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?

simoncolumbus
  • 526
  • 1
  • 8
  • 23

1 Answers1

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.

Fei YE
  • 421
  • 3
  • 9
  • 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! – MartineJ Jan 09 '21 at 14:14
  • Hi Martine, did you try `.tfoot .td { background-color: white}`? – Fei YE Jan 11 '21 at 17:17
  • 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. – MartineJ Jan 15 '21 at 14:22
  • 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. – Fei YE Feb 06 '21 at 21:22