标题字体颜色与kable

Ani*_*Ani 7 css r knitr r-markdown

使用kable()呈现一个简单的表会产生似乎是生成的html文件中表标题的默认淡色字体颜色.有没有办法控制表(或图)标题字体的颜色,大小等?

    ---
    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")
    ```
Run Code Online (Sandbox Code Playgroud)

Ani*_*Ani 6

啊哈!自定义CSS样式表可以解决问题.

    caption {
      color: red;
      font-weight: bold;
      font-size: 1.0em;
    } 
Run Code Online (Sandbox Code Playgroud)


Nov*_*ova 5

添加到 Ani 的答案:如果您不想单独编写 css 样式表,您可以在 YAML 之后包含另一个块:

```{r results="asis"}
cat("
<style>
caption {
      color: red;
      font-weight: bold;
      font-size: 1.0em;
    }
</style>
")
```
Run Code Online (Sandbox Code Playgroud)