gt (version 0.8.0)

tab_header: Add a table header

Description

We can add a table header to the gt table with a title and even a subtitle. A table header is an optional table part that is positioned above the column labels. We have the flexibility to use Markdown formatting for the header's title and subtitle. Furthermore, if the table is intended for HTML output, we can use HTML in either of the title or subtitle.

Usage

tab_header(data, title, subtitle = NULL, preheader = NULL)

Value

An object of class gt_tbl.

Arguments

data

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

title, subtitle

Text to be used in the table title and, optionally, for the table subtitle. We can elect to use the md() and html() helper functions to style the text as Markdown or to retain HTML elements in the text.

preheader

Optional preheader content that is rendered above the table. Can be supplied as a vector of text.

Examples

Use gtcars to create a gt table. Add a header part with the tab_header() function so that we get a title and a subtitle for the table.

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")
  )

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

Function ID

2-1

See Also

Other part creation/modification functions: tab_caption(), tab_footnote(), 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()