opt_stylize: Stylize your table with a colorful look

View source: R/opts.R

opt_stylizeR Documentation

Stylize your table with a colorful look


With opt_stylize() you can quickly style your gt table with a carefully curated set of background colors, line colors, and line styles. There are six styles to choose from and they largely vary in the extent of coloring applied to different table locations. Some have table borders applied, some apply darker colors to the table stub and summary sections, and, some even have vertical lines. In addition to choosing a style preset, there are six color variations that each use a range of five color tints. Each of the color tints have been fine-tuned to maximize the contrast between text and its background. There are 36 combinations of style and color to choose from.


opt_stylize(data, style = 1, color = "blue", add_row_striping = TRUE)



The gt table data object

⁠obj:<gt_tbl>⁠ // required

This is the gt table object that is commonly created through use of the gt() function.


Table style

⁠scalar<numeric|integer>(1>=val>=6)⁠ // default: 1

Six numbered styles are available. Simply provide a number from 1 (the default) to 6 to choose a distinct look.


Color variation

⁠scalar<character>⁠ // default: "blue"

There are six color variations: "blue", "cyan", "pink", "green", "red", and "gray".


Allow row striping

⁠scalar<logical>⁠ // default: TRUE

An option to enable row striping in the table body for the style chosen.


an object of class gt_tbl.


Use exibble to create a gt table with a number of table parts added. Then, use the opt_stylize() function to give the table some additional style (using the "cyan" color variation and style number 6).

exibble |>
  gt(rowname_col = "row", groupname_col = "group") |>
    groups = "grp_a",
    columns = c(num, currency),
    fns = c("min", "max")
  ) |>
    columns = currency,
    fns = total ~ sum(., na.rm = TRUE)
  ) |>
  tab_source_note(source_note = "This is a source note.") |>
    footnote = "This is a footnote.",
    locations = cells_body(columns = 1, rows = 1)
  ) |>
    title = "The title of the table",
    subtitle = "The table's subtitle"
  ) |>
  opt_stylize(style = 6, color = "cyan")
This image of a table was generated from the first code example in the `opt_stylize()` help file.

Function ID


Function Introduced

v0.7.0 (Aug 25, 2022)

See Also

Other table option functions: opt_align_table_header(), opt_all_caps(), opt_css(), opt_footnote_marks(), opt_footnote_spec(), opt_horizontal_padding(), opt_interactive(), opt_row_striping(), opt_table_font(), opt_table_lines(), opt_table_outline(), opt_vertical_padding()

gt documentation built on June 22, 2024, 11:11 a.m.