Search code examples
r-markdownkablekableextrafootnotes

kableExtra: Change font size of table footnote


I'd like for my font size in the footnotes to be smaller than the text in the table, but can't figure it out. Is there something similar to kable_styling where I can edit the text and color of rows in the table that can be used for footnotes? I am using RMarkdown to generate the HTML not 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`

Solution

  • You could use the html <small> tag in the text for the general and general_title parameters of the kabaleExtra::footnote function. See example:

    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
      )