Skip to contents

The opt_table_font() function makes it possible to define a custom font for the entire gt table. The standard fallback fonts are still set by default but the font defined here will take precedence. You could still have different fonts in select locations in the table, and for that you would need to use tab_style() in conjunction with the cell_text() helper function.


opt_table_font(data, font, weight = NULL, style = NULL, add = TRUE)



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


Either the name of a font available in the user system or a call to google_font(), which has a large selection of typefaces.


The weight of the font. Can be a text-based keyword such as "normal", "bold", "lighter", "bolder", or, a numeric value between 1 and 1000, inclusive. Note that only variable fonts may support the numeric mapping of weight.


The text style. Can be one of either "normal", "italic", or "oblique".


Should this font be added to the front of the already-defined fonts for the table? By default, this is TRUE and is recommended since the list serves as fallbacks when certain fonts are not available.


An object of class gt_tbl.


We have the option to supply either a system font for the font_name, or, a font available at the Google Fonts service by use of the google_font() helper function.


Use sp500 to create a small gt table, using fmt_currency() to provide a dollar sign for the first row of monetary values. Then, set a larger font size for the table and use the "Merriweather" font (from Google Fonts, via google_font()) with two font fallbacks ("Cochin" and the catchall "Serif" group).

sp500 %>%
  dplyr::slice(1:10) %>%
  dplyr::select(-volume, -adj_close) %>%
  gt() %>%
    columns = 2:5,
    rows = 1,
    currency = "USD",
    use_seps = FALSE
  ) %>%
  tab_options(table.font.size = px(18)) %>%
    font = list(
      google_font(name = "Merriweather"),
      "Cochin", "Serif"

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

Use sza to create an eleven-row table. Within opt_table_font(), set up a preferred list of sans-serif fonts that are commonly available in macOS (using part of the default_fonts() vector as a fallback).

sza %>%
    latitude == 20 &
      month == "jan" &
  ) %>%
  dplyr::select(-latitude, -month) %>%
  gt() %>%
    font = c(
      "Helvetica Neue", "Segoe UI",
  ) %>%

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

Function ID