Reputation: 303
I'm preparing a PDF file using RMarkdown and I want to color a specific cell in red using kableExtra
and cell_spec
. I am able to color whole row (row_spec
) or column (column_spec
) but I was not able to do it with cell_spec
.
Here is the code I used to color the first row:
knitr::kable((mtcars), booktabs = TRUE) %>%
row_spec(1, bold = FALSE, color = "red")
Is it possible to color a single cell (mtcars[1,1]
) to red?
Upvotes: 0
Views: 1800
Reputation: 1769
You can use cell_spec
as follows to set cell(1,1) to red
cs_dt = mtcars
cs_dt[1,1] = cell_spec(cs_dt[1,1], color = "red")
kbl(cs_dt, booktabs = T, escape = F)
Upvotes: 1