【问题标题】:Caption font color with kable带有 kable 的字幕字体颜色
【发布时间】:2016-03-30 12:08:37
【问题描述】:

使用 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")
    ```

【问题讨论】:

    标签: css r knitr r-markdown


    【解决方案1】:

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

        caption {
          color: red;
          font-weight: bold;
          font-size: 1.0em;
        } 
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        【解决方案3】:

        现在您可以绕过 R 直接使用 css 代码块。添加 echo = FALSE 可以防止它成为输出的一部分。

        ```{css, echo = FALSE}
        caption {
              color: red;
              font-weight: bold;
              font-size: 1.0em;
            }
        ```
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-08-01
          • 2012-08-28
          • 1970-01-01
          • 2013-11-19
          • 2017-02-26
          • 1970-01-01
          相关资源
          最近更新 更多