Reputation: 615
I want to display alternating row colors using knitr:kable
in R Markdown rendering PDF with xelatex
. E.g.
knitr::kable(mtcars,format="markdown")
Upvotes: 0
Views: 5881
Reputation: 3252
This uses the package kableExtra
---
title: "Habits"
output: html_document
---
<style>
.striped tr:nth-child(even) { background: #00ff00; }
</style>
```{r message=FALSE, warning=FALSE, echo = FALSE}
library(kableExtra)
kable(mtcars[1:15, 1:4], table.attr = "class=\"striped\"",
format = "html")
```
This will give you an HTML output, but you can simply just "Print to PDF" from the browser
Upvotes: 1
Reputation: 7856
You can do it with kableExtra
knitr::kable(mtcars, "html") %>%
kable_styling("striped")
or
knitr::kable(mtcars, "latex") %>%
kable_styling(latex_options = "striped")
Upvotes: 2