Skip to contents

This function creates stacked column headers in a gt table, where each column has a customizable main heading and subtitle, along with options to set the colors and font weights for both the heading and subtitle.

Usage

gt_column_subheaders(
  gt_table,
  heading_color = "black",
  subtitle_color = "#808080",
  heading_weight = "bold",
  subtitle_weight = "normal",
  ...
)

Arguments

gt_table

A gt table object to modify.

heading_color

Character. Color for the main heading text. Defaults to "black".

subtitle_color

Character. Color for the subtitle text. Defaults to "#808080".

heading_weight

Character. Font weight for the main heading. Defaults to "bold".

subtitle_weight

Character. Font weight for the subtitle. Defaults to "normal".

...

Named arguments where each name corresponds to a column in the gt table and each value is a list containing two elements: heading (the main heading) and subtitle (the subtitle text). If a column is not included, it will use the column name as the heading and display a non-breaking space ( ) as the subtitle.

Value

Returns a modified gt table with stacked headers and subtitles.

Details

The function iterates over the columns of the gt table and applies a two-level header for each column: a customizable main heading and a smaller, customizable subtitle. If no subtitle or heading is provided for a column, the column name is used as the heading and a default non-breaking space is used as the subtitle.

Examples

# mtcars %>%
#   head() %>%
#   gt() %>%
#   gt_column_subheaders(
#     mpg = list(heading = "Top", subtitle = "Bottom"),
#     hp = list(heading = "Horsepower", subtitle = "HP"),
#     heading_color = "blue", subtitle_color = "gray"
#   )