带有 kable 的字幕字体颜色
Caption font color with kable
使用 kable() 渲染一个简单的 table 会产生似乎是生成的 html 文件中 table 标题的默认淡字体颜色。有没有办法控制 table (或数字)标题字体颜色、大小等?
---
title: "test"
output:
html_document:
theme: cosmo
---
```{r}
library(knitr)
tab.1 = table(mtcars$cyl, mtcars$vs)
kable(tab.1, caption="Table 1: Caption Font Color")
```
啊哈!自定义 CSS 样式表就可以了。
caption {
color: red;
font-weight: bold;
font-size: 1.0em;
}
添加到 Ani 的回答:如果您不想单独编写 css 样式表,您可以在 YAML 之后包含另一个块:
```{r results="asis"}
cat("
<style>
caption {
color: red;
font-weight: bold;
font-size: 1.0em;
}
</style>
")
```
现在您可以绕过 R 直接使用 css
代码块。添加 echo = FALSE
可以防止它成为输出的一部分。
```{css, echo = FALSE}
caption {
color: red;
font-weight: bold;
font-size: 1.0em;
}
```
使用 kable() 渲染一个简单的 table 会产生似乎是生成的 html 文件中 table 标题的默认淡字体颜色。有没有办法控制 table (或数字)标题字体颜色、大小等?
---
title: "test"
output:
html_document:
theme: cosmo
---
```{r}
library(knitr)
tab.1 = table(mtcars$cyl, mtcars$vs)
kable(tab.1, caption="Table 1: Caption Font Color")
```
啊哈!自定义 CSS 样式表就可以了。
caption {
color: red;
font-weight: bold;
font-size: 1.0em;
}
添加到 Ani 的回答:如果您不想单独编写 css 样式表,您可以在 YAML 之后包含另一个块:
```{r results="asis"}
cat("
<style>
caption {
color: red;
font-weight: bold;
font-size: 1.0em;
}
</style>
")
```
现在您可以绕过 R 直接使用 css
代码块。添加 echo = FALSE
可以防止它成为输出的一部分。
```{css, echo = FALSE}
caption {
color: red;
font-weight: bold;
font-size: 1.0em;
}
```