Consider this example
---
title: "R Notebook"
output:
pdf_document: default
---
Hello this is a nice test
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
options(knitr.table.format = "latex")
library(knitr)
library(kableExtra)
library(dplyr)
# needed
kable(cars, "latex") %>% kable_styling(bootstrap_options = "striped")
```
here we go
```{r, results = "asis"}
for (threshold in c(20, 25)) {
cat("\n\n\\pagebreak\n")
x <- mtcars %>%
filter(mpg < threshold) %>%
mutate(disp = cell_spec(
disp, "latex", color = "white", bold = T,
background = spec_color(1:10, end = 0.9, option = "A")
)) %>%
kable('latex', booktabs = T, escape=F) %>%
kable_styling(latex_options = c("striped", "hold_position"),
full_width = T) %>%
column_spec(1, bold = T, color = "red") %>%
add_header_above(c(" ", "$\\\\beta$" = 10), escape = F)
cat(x)
}
```
I am trying to use the trick explained here how to use a for loop in rmarkdown? to use all the raw power in kableExtra
in my pdfs.
This is a pretty nice example of how to generate a dynamic rmarkdown document that creates tables in a for loop.
Nice indeed, except for the cell_specs
gradient that contais some mysterious white spaces...
Any ideas?
Thanks!