Learn R Programming

gt (version 0.8.0)

tab_caption: Add a table caption

Description

Add a caption to a gt table, which is handled specially for a table within an R Markdown, Quarto, or bookdown context. The addition of captions makes tables cross-referencing across the containing document. The caption location (i.e., top, bottom, margin) is handled at the document level in each of these system.

Usage

tab_caption(data, caption)

Value

An object of class gt_tbl.

Arguments

data

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

caption

The table caption to use for cross-referencing in R Markdown, Quarto, or bookdown.

Examples

Use gtcars to create a gt table. Add a header part with the tab_header() function, and, add a caption as well with tab_caption().

gtcars %>%
  dplyr::select(mfr, model, msrp) %>%
  dplyr::slice(1:5) %>%
  gt() %>%
  tab_header(
    title = md("Data listing from **gtcars**"),
    subtitle = md("`gtcars` is an R dataset")
  ) %>%
  tab_caption(caption = md("**gt** table example."))

This image of a table was generated from the first code example in the `tab_caption()` help file.

Function ID

2-9

See Also

Other part creation/modification functions: tab_footnote(), tab_header(), tab_info(), tab_options(), tab_row_group(), tab_source_note(), tab_spanner_delim(), tab_spanner(), tab_stub_indent(), tab_stubhead(), tab_style_body(), tab_style()