I want a blue caption then a red caption. I cat
two HTML <style>...</style>
sections, first blue second red, according to this answer, but I get both red.
How to get a blue then a red caption?
---
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=FALSE)
```
```{r results="asis"}
cat("
<style>
caption {
color: blue;
}
</style>
")
knitr::kable(head(iris),
format="html",
digits=4,
row.names=FALSE,
caption='Caption blue',
escape=TRUE)|>
kableExtra::kable_styling(font_size=14) |>
kableExtra::kable_paper(c('hover', 'condensed', 'responsive'), full_width=T) |>
kableExtra::scroll_box(width="100%", height="200px")
```
```{r results="asis"}
cat("
<style>
caption {
color: red;
}
</style>
")
knitr::kable(head(iris),
format="html",
digits=4,
row.names=FALSE,
caption='Caption red',
escape=TRUE) |>
kableExtra::kable_styling(font_size=14) |>
kableExtra::kable_paper(c('hover', 'condensed', 'responsive'), full_width=T) |>
kableExtra::scroll_box(width="100%", height="200px")
```
2
Answers
Because second css overwrites the first css.
Better to do like this:
and then use like this:
Works?
Regards,
Noel
Rather than specifying the CSS in each chunk, you can also give a special HTML class to each table and then gather all styling in a
css
chunk:Alternatively we could insert inline css outside of a chunk.