kableExtra:更改表格脚注的字体大小

时间:2020-02-11 20:03:05

标签: r-markdown kable kableextra footnotes

我希望脚注中的字体大小小于表格中的文本,但无法弄清楚。有什么类似于kable_styling的地方,我可以编辑表中可用作脚注的行的文本和颜色吗?我正在使用RMarkdown生成HTML,而不是LateX。

enter image description here

---
title: "Untitled"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE )

library( kableExtra )
library( knitr ) 

```

```{r mtcars}

 tab_mtcars <- knitr::kable( mtcars[ 1:5 , c( 1:4 )] , format = "html", col.names = c( "MPG", "CYL", "DISP" , "HP" ) ,  align = "lccc" , escape = F ) %>% kable_styling( full_width = T , bootstrap_options = c( "hover", "condensed" , "bordered"), position = "left") %>% add_header_above( c( "mtcars example" = 5 ) , bold = TRUE ) %>% footnote( general = c( "Here is the footnote where I would like font smaller than above" ),     general_title = "Note: ", footnote_as_chunk = T )

```

`r tab_mtcars`

2 个答案:

答案 0 :(得分:5)

您可以在文本中使用html <small>标签作为general函数的general_titlekabaleExtra::footnote参数。参见示例:

tab_mtcars <-
  knitr::kable(
    mtcars[1:5 , c(1:4)] ,
    format = "html",
    col.names = c("MPG", "CYL", "DISP" , "HP") ,
    align = "lccc" ,
    escape = F
  ) %>%
  kable_styling(
    full_width = T ,
    bootstrap_options = c("hover", "condensed" , "bordered"),
    position = "left"
  ) %>% add_header_above(c("mtcars example" = 5) , bold = TRUE) %>% footnote(
    general = c(
      "<small>Here is the footnote where I would like font smaller than above</small>"
    ),
    general_title = "<small>Note: </small>",
    footnote_as_chunk = T ,
    escape = F
  )

答案 1 :(得分:1)

似乎没有一种方法可以从<div class="button-box"> <a href="#" class="btn btn--white">The Crazy Button</a> </div>进行控制,因此您可以更改CSS样式。使用以下YAML:

kable()

和同一文件夹中的style.css文件,其中包含一些CSS代码:

---
title: "Untitled"
output:
  html_document:
    css: style.css
---

enter image description here