The google_font() function

Use the exibble dataset to create a gt table of two columns and eight rows. We’ll replace missing values with em dashes using sub_missing(). For text in the time column, we will use the font called "IBM Plex Mono" which is available in Google Fonts. This is defined inside the google_font() call, itself part of a vector that includes fonts returned by default_fonts() (those fonts will serve as fallbacks just in case the font supplied by Google Fonts is not accessible). In terms of placement, all of this is given to the font argument of cell_text() which is itself given to the style argument of tab_style().

exibble |>
  dplyr::select(char, time) |>
  gt() |>
  sub_missing() |>
  tab_style(
    style = cell_text(
      font = c(
        google_font(name = "IBM Plex Mono"),
        default_fonts()
      )
    ),
    locations = cells_body(columns = time)
  )
char time
apricot 13:35
banana 14:40
coconut 15:45
durian 16:50
17:55
fig
grapefruit 19:10
honeydew 20:20

We can use a subset of the sp500 dataset to create a small gt table. With fmt_currency(), we can display a dollar sign for the first row of the monetary values. Then, we’ll set a larger font size for the table and opt to use the "Merriweather" font by calling google_font() within opt_table_font(). In cases where that font may not materialize, we include two font fallbacks: "Cochin" and the catchall "Serif" group.

sp500 |>
  dplyr::slice(1:10) |>
  dplyr::select(-volume, -adj_close) |>
  gt() |>
  fmt_currency(
    rows = 1,
    currency = "USD",
    use_seps = FALSE
  ) |>
  tab_options(table.font.size = px(20)) |>
  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