The cell_text() function

Let’s use the exibble dataset to create a simple, two-column gt table (keeping only the num and currency columns). With tab_style() (called twice), we’ll selectively add style to the values formatted with fmt_number(). We do this by using cell_text() in the style argument of tab_style().

exibble |>
  dplyr::select(num, currency) |>
  gt() |>
  fmt_number(decimals = 1) |>
  tab_style(
    style = cell_text(weight = "bold"),
    locations = cells_body(
      columns = num,
      rows = num >= 5000
    )
  ) |>
  tab_style(
    style = cell_text(style = "italic"),
    locations = cells_body(
      columns = currency,
      rows = currency < 100
    )
  )
num currency
0.1 50.0
2.2 17.9
33.3 1.4
444.4 65,100.0
5,550.0 1,325.8
NA 13.3
777,000.0 NA
8,880,000.0 0.4