Here is a demonstration of package kableExtra. As I said in #1132, this package is still in early stage and I basically only finished coding for add_footnote and some supporting functions.

library(knitr)
library(kableExtra)

library(dplyr)
library(ezsummary) #for quick summary generation
opts_chunk$set(echo = TRUE)

A quick demo

Here is a quick demo of using add_footnote when the user customization level is minimal. You can see add_footnote can work with the default markdown/pandoc output and alter its result. If people don’t like to use 123 as the notation, they have the option to switch to abc or *†‡ by setting the option notation to be either “alphabet” or “symbol” (the default is “number”). People can have upto 20 footnotes.

mtcars %>%
  select(mpg, cyl, disp, hp) %>%
  ezsummary() %>%
  kable(caption = "Summary of mtcars") %>%
  add_footnote("This is the minimum sample of using add_footnote. ")
Summary of mtcars
variable mean sd
mpg 20.091 6.027
cyl 6.188 1.786
disp 230.722 123.939
hp 146.688 68.563

Note: 1 This is the minimum sample of using add_footnote.

Features

In table notation

In kableExtra, if users want to have in-table notation to the footnotes, they need to define them before they pass things into kable by putting a “[note]” at the places where they want to have the notations. In most cases, people can do it when they are fixing the row names.

dt <- mtcars %>%
  select(mpg, cyl, disp, hp) %>%
  ezsummary() %>%
  mutate(
    variable = c("MPG [note]", "Engine Cylinder [note]",
                 "Displacement", "Horsepower")
    ) 

dt %>%
  kable(caption = "Summary of mtcars [note]") %>%
  add_footnote(
    c("The data was extracted from the 1974 Motor Trend US magazine",
      "Miles per gallon", "Possible values: 4, 6, 8"), 
    notation = "symbol"
  )
Summary of mtcars *
variable mean sd
MPG 20.091 6.027
Engine Cylinder 6.188 1.786
Displacement 230.722 123.939
Horsepower 146.688 68.563

Note: * The data was extracted from the 1974 Motor Trend US magazine Miles per gallon Possible values: 4, 6, 8

If the number of in-table notations does not match the number of footnote labels, add_footnote will throw a warning to indicate that there is probably an mistake somewhere.

dt %>%
  kable(caption = "Summary of mtcars") %>% 
  # I just removed the [note] in the table caption
  add_footnote(
    c("The data was extracted from the 1974 Motor Trend US magazine",
      "Miles per gallon", "Possible values: 4, 6, 8"), 
    notation = "symbol"
  )
## Warning in add_footnote(., c("The data was extracted from the 1974 Motor
## Trend US magazine", : You entered 3 labels but you put 2 [note] in your
## table.
Summary of mtcars
variable mean sd
MPG * 20.091 6.027
Engine Cylinder 6.188 1.786
Displacement 230.722 123.939
Horsepower 146.688 68.563

Note: * The data was extracted from the 1974 Motor Trend US magazine Miles per gallon Possible values: 4, 6, 8

If users wants to add repeated notations, they can use something like [note1] (up to [note20]) to indicate that.

dt %>%
  kable(caption = "[note]Summary[note] of mtcars[note1]") %>%
  add_footnote(
    c("The data was extracted from the 1974 Motor Trend US magazine",
      "random footnote",
      "Miles per gallon", "Possible values: 4, 6, 8"), 
    notation = "symbol"
  )
* Summary of mtcars*
variable mean sd
MPG 20.091 6.027
Engine Cylinder § 6.188 1.786
Displacement 230.722 123.939
Horsepower 146.688 68.563

Note: * The data was extracted from the 1974 Motor Trend US magazine random footnote Miles per gallon § Possible values: 4, 6, 8

Better Formatting when format is defined in kable

If people define format to be html when they are using kable, they may enjoy a cleaner table footnote format as well because this time everything is organized into the

tag and the linespace is set to be single.

dt %>%
  kable(caption = "Summary of mtcars [note]", format = "html",
        table.attr = "class = 'table table-striped table-hover'") %>% 
  add_footnote(
    c("The data was extracted from the 1974 Motor Trend US magazine",
      "Miles per gallon", "Possible values: 4, 6, 8"), 
    notation = "symbol"
  )
Summary of mtcars *
variable mean sd
MPG 20.091 6.027
Engine Cylinder 6.188 1.786
Displacement 230.722 123.939
Horsepower 146.688 68.563
* The data was extracted from the 1974 Motor Trend US magazine
Miles per gallon
Possible values: 4, 6, 8