I am trying to change the background color of table headers in R Markdown knitted to Slidy HTML. I use xtable
for the output and found it easiest with CSS over other methods. I decided to go with a CSS chunk instead of a CSS file.
---
title: "Test"
output: slidy_presentation
---
```{r setup, include = F}
library(xtable)
```
CSS chunk
```{css, header, echo = F}
th {
background: orange;
}
```
Table output
# Table output
```{r table, results = "asis", echo = F}
df <- data.frame("Col.A" = 1:3, "Col.B" = 4:6)
print(xtable(df), type = "HTML", include.rownames = F)
```
Here's the table with headers in orange. However, with {css, echo = F}
, there's a blank page between the title page (#1) and the actual output (#3). I also notice, on the upper left corner in output, it reads Table output (3/2). 3/2... On the blank page, it reads Table output (2/2). And there is not a 3/2 in the dropdown. I need to mouse click to advance to page 3 (the actual output). In the Table of Contents, however, there are three pages, Test (the title page), Test(2), and Table output.
If I use {css, include = F}
, the blank page was gone (just the title page and the output page) and so was the background color of the table headers.
I found in another thread, someone also recommended a CSS chunk without any indication of a blank page with such a method. How do I change the background color of the table headers without a blank page? Thank you!