The opt_table_font() function

Use a subset of the sp500 dataset to create a small gt table. We’ll use fmt_currency() to display a dollar sign for the first row of monetary values. The "Merriweather" font (from Google Fonts, via google_font()) with two system font fallbacks ("Cochin" and the generic "serif").

sp500 |>
  dplyr::slice(1:10) |>
  dplyr::select(-volume, -adj_close) |>
  gt() |>
  fmt_currency(
    rows = 1,
    use_seps = FALSE
  ) |>
  opt_table_font(
    font = list(
      google_font(name = "Merriweather"),
      "Cochin", "serif"
    )
  )
date open high low close
2015-12-31 $2060.59 $2062.54 $2043.62 $2043.94
2015-12-30 2077.34 2077.34 2061.97 2063.36
2015-12-29 2060.54 2081.56 2060.54 2078.36
2015-12-28 2057.77 2057.77 2044.20 2056.50
2015-12-24 2063.52 2067.36 2058.73 2060.99
2015-12-23 2042.20 2064.73 2042.20 2064.29
2015-12-22 2023.15 2042.74 2020.49 2038.97
2015-12-21 2010.27 2022.90 2005.93 2021.15
2015-12-18 2040.81 2040.81 2005.33 2005.55
2015-12-17 2073.76 2076.37 2041.66 2041.89

With the sza dataset we’ll create a two-column, eleven-row table. Within opt_table_font(), the stack argument will be supplied with the "rounded-sans" font stack. This sets up a family of fonts with rounded, curved letterforms that should be locally available in different computing environments.

sza |>
  dplyr::filter(
    latitude == 20 &
      month == "jan" &
      !is.na(sza)
  ) |>
  dplyr::select(-latitude, -month) |>
  gt() |>
  opt_table_font(stack = "rounded-sans") |>
  opt_all_caps()
tst sza
0700 84.9
0730 78.7
0800 72.7
0830 66.1
0900 61.5
0930 56.5
1000 52.1
1030 48.3
1100 45.5
1130 43.6
1200 43.0