Open ghost opened 2 years ago
So glad to see this issue! It seems full_width and stripes or cell background edits don't work well together.
I found the same problem with full_width and striped rows... Was going crazy trying to add the stripes. They only appear when kable_styling(full_width = F)
.
Strangely, something like: row_spec(seq(1,nrow(data_prospective),2), **color**="red")
works, paired with kable_styling (full_width = T)
but row_spec(seq(1,nrow(data_prospective),2), **background**="red")
doesn't
This has stripes showing when rendered with pdf:
data_prospective %>%
kbl(., booktabs = T, longtable = T) %>%
kable_styling(latex_options = c("striped","repeat_header"),
full_width = F,
font_size = 8) %>%
column_spec(column = 4, width = "5cm")
The same issue of incompatibility between kable_styling
and column_spec
happens for me. A somewhat simplified example is the following:
---
title: "DEMO"
output:
pdf_document:
latex_engine: xelatex
---
```{r, echo=FALSE}
library(kableExtra)
options(knitr.table.format = "latex")
kbl(mtcars[1:7, ], align = "c", booktabs = TRUE, linesep = "") %>%
kable_styling(latex_options = c("striped", "HOLD_position"), full_width = TRUE) %>%
column_spec(1, width = "4cm")
This produces a table without the striping:
The striping is correctly present when full_width = FALSE
.
I believe that this is an upstream problem with the tabu
package in LaTeX:
https://tex.stackexchange.com/questions/496541/using-cellcolor-with-tabu https://tex.stackexchange.com/questions/494689/color-rows-on-table-tabu-package
A column in a table should have a background color. When using
full_width = TRUE
the background color does not appear. As you can see in the output the cells are marked with\cellcolor{green}
but in the pdf output the column is not green. Also I can see in the output that the first row of the colored column has not this tag\cellcolor{green}
, which will be most likely the next problem. When thefull_width = TRUE
is removed the column gets coloured but not for the first row (as expected).