The tab_options() function

Use exibble to create a gt table with all the main parts added. We can use this gt object going forward to demo some of what’s available in the tab_options() function.

tab_1 <-
  exibble |>
  dplyr::select(-c(fctr, date, time, datetime)) |>
  gt(
    rowname_col = "row",
    groupname_col = "group"
  ) |>
  tab_header(
    title = md("Data listing from **exibble**"),
    subtitle = md("`exibble` is an R dataset")
  ) |>
  fmt_number(columns = num) |>
  fmt_currency(columns = currency) |>
  tab_footnote(
    footnote = "Using commas for separators.",
    locations = cells_body(
      columns = num,
      rows = num > 1000
    )
  ) |>
  tab_footnote(
    footnote = "Using commas for separators.",
    locations = cells_body(
      columns = currency,
      rows = currency > 1000
    )
  ) |>
  tab_footnote(
    footnote = "Alphabetical fruit.",
    locations = cells_column_labels(columns = char)
  )

tab_1
Data listing from exibble
exibble is an R dataset
num char1 currency
grp_a
row_1 0.11 apricot $49.95
row_2 2.22 banana $17.95
row_3 33.33 coconut $1.39
row_4 444.40 durian 2 $65,100.00
grp_b
row_5 2 5,550.00 NA 2 $1,325.81
row_6 NA fig $13.26
row_7 2 777,000.00 grapefruit NA
row_8 2 8,880,000.00 honeydew $0.44
1 Alphabetical fruit.
2 Using commas for separators.

Modify the table width to be 100% (which spans the entire content width area).

tab_1 |> tab_options(table.width = pct(100))
Data listing from exibble
exibble is an R dataset
num char1 currency
grp_a
row_1 0.11 apricot $49.95
row_2 2.22 banana $17.95
row_3 33.33 coconut $1.39
row_4 444.40 durian 2 $65,100.00
grp_b
row_5 2 5,550.00 NA 2 $1,325.81
row_6 NA fig $13.26
row_7 2 777,000.00 grapefruit NA
row_8 2 8,880,000.00 honeydew $0.44
1 Alphabetical fruit.
2 Using commas for separators.

Modify the table’s background color to be "lightcyan".

tab_1 |> tab_options(table.background.color = "lightcyan")
Data listing from exibble
exibble is an R dataset
num char1 currency
grp_a
row_1 0.11 apricot $49.95
row_2 2.22 banana $17.95
row_3 33.33 coconut $1.39
row_4 444.40 durian 2 $65,100.00
grp_b
row_5 2 5,550.00 NA 2 $1,325.81
row_6 NA fig $13.26
row_7 2 777,000.00 grapefruit NA
row_8 2 8,880,000.00 honeydew $0.44
1 Alphabetical fruit.
2 Using commas for separators.

Use letters as the marks for footnote references. Also, separate footnotes in the footer by spaces instead of newlines.

tab_1 |>
  tab_options(
    footnotes.marks = letters,
    footnotes.multiline = FALSE
  )
Data listing from exibble
exibble is an R dataset
num chara currency
grp_a
row_1 0.11 apricot $49.95
row_2 2.22 banana $17.95
row_3 33.33 coconut $1.39
row_4 444.40 durian b $65,100.00
grp_b
row_5 b 5,550.00 NA b $1,325.81
row_6 NA fig $13.26
row_7 b 777,000.00 grapefruit NA
row_8 b 8,880,000.00 honeydew $0.44
a Alphabetical fruit. b Using commas for separators.

Change the padding of data rows to 5 px.

tab_1 |>
  tab_options(
    data_row.padding = px(5)
  )
Data listing from exibble
exibble is an R dataset
num char1 currency
grp_a
row_1 0.11 apricot $49.95
row_2 2.22 banana $17.95
row_3 33.33 coconut $1.39
row_4 444.40 durian 2 $65,100.00
grp_b
row_5 2 5,550.00 NA 2 $1,325.81
row_6 NA fig $13.26
row_7 2 777,000.00 grapefruit NA
row_8 2 8,880,000.00 honeydew $0.44
1 Alphabetical fruit.
2 Using commas for separators.

Reduce the size of the title and the subtitle text.

tab_1 |>
  tab_options(
    heading.title.font.size = "small",
    heading.subtitle.font.size = "small"
  )
Data listing from exibble
exibble is an R dataset
num char1 currency
grp_a
row_1 0.11 apricot $49.95
row_2 2.22 banana $17.95
row_3 33.33 coconut $1.39
row_4 444.40 durian 2 $65,100.00
grp_b
row_5 2 5,550.00 NA 2 $1,325.81
row_6 NA fig $13.26
row_7 2 777,000.00 grapefruit NA
row_8 2 8,880,000.00 honeydew $0.44
1 Alphabetical fruit.
2 Using commas for separators.