The tab_footnote() function can make it a painless process to add a footnote to a gt table. There are two components to a footnote: (1) a footnote mark that is attached to the targeted cell text, and (2) the footnote text (that starts with the corresponding footnote mark) that is placed in the table's footer area. Each call of tab_footnote() will add a different note, and one or more cells can be targeted via the location helper functions (e.g., cells_body(), cells_column_labels(), etc.).

tab_footnote(data, footnote, locations)

Arguments

data

A table object that is created using the gt() function.

footnote

The text to be used in the footnote. We can optionally use the md() and html() functions to style the text as Markdown or to retain HTML elements in the footnote text.

locations

The cell or set of cells to be associated with the footnote. Supplying any of the cells_*() helper functions is a useful way to target the location cells that are associated with the footnote text. These helper functions are: cells_title(), cells_stubhead(), cells_column_spanners(), cells_column_labels(), cells_row_groups(), cells_stub(), cells_body(), cells_summary(), and cells_grand_summary(). Additionally, we can enclose several cells_*() calls within a list() if we wish to link the footnote text to different types of locations (e.g., body cells, row group labels, the table title, etc.).

Value

An object of class gt_tbl.

Details

The formatting of the footnotes can be controlled through the use of various parameters in the tab_options() function:

  • footnotes.sep: allows for a choice of the separator between consecutive footnotes in the table footer. By default, this is set to a linebreak.

  • footnotes.marks: the set of sequential characters or numbers used to identify the footnotes.

  • footnotes.font.size: the size of the font used in the footnote section.

  • footnotes.padding: the amount of padding to apply between the footnote and source note sections in the table footer.

Figures

Function ID

2-6

See also

Examples

# Use `sza` to create a gt table; color # the `sza` column using the `data_color()` # function, then, add a footnote to the # `sza` column label explaining what the # color scale signifies tab_1 <- sza %>% dplyr::filter( latitude == 20 & month == "jan" & !is.na(sza) ) %>% dplyr::select(-latitude, -month) %>% gt() %>% data_color( columns = vars(sza), colors = scales::col_numeric( palette = c("white", "yellow", "navyblue"), domain = c(0, 90)) ) %>% tab_footnote( footnote = "Color indicates height of sun.", locations = cells_column_labels( columns = vars(sza)) )