Skip to contents

Three horizontal rules and nothing else, the way LaTeX booktabs draws them. A heavy rule sits above the column labels, a lighter one below them, and a heavy rule closes the body. There are no vertical rules, no rules between data rows, and no fills. The type is a Times-compatible serif.

Usage

gt_theme_booktabs(
  gt_object,
  accent = "#111111",
  density = c("comfortable", "compact", "social"),
  ...
)

Arguments

gt_object

A gt table object to modify.

accent

Character. A hex color for the three rules and the row-group labels. Defaults to "#111111", near-black, for the standard black rules.

density

Character. The type and padding scale. One of "comfortable", "compact", or "social". See Density. Defaults to "comfortable".

...

Additional arguments passed to gt::tab_options, applied last so they override anything the theme sets.

Value

Returns a modified gt table with the theme applied.

Details

accent recolors the three rules and the row-group labels.

Density

density sets the type and padding scale together. "comfortable" uses a 14px body with roomy rows, "compact" a 12px body with tight rows, and "social" a 17px body with generous rows and a larger title, at the scale gt_save_crop() and gt_social_crop() export at.

Figures

Preview of the booktabs theme

See also

gt_theme_tufte() for a lighter, minimal-ink relative, and gt_significance() for significance notation.

Examples

library(gt)

afc_west <- subset(
  sdv_example_standings, division == "AFC West",
  c(team_name, wins:points_against)
)
gt(afc_west) |> gt_theme_booktabs()
team_name wins losses ties win_pct points_for points_against
Denver Broncos 14 3 0 0.824 401 311
Los Angeles Chargers 11 6 0 0.647 368 340
Kansas City Chiefs 6 11 0 0.353 362 328
Las Vegas Raiders 3 14 0 0.176 241 432
# a regression table, with significance stars and a colored rule nfl <- subset(sdv_example_standings, league == "nfl") fit <- lm(win_pct ~ points_for + points_against, data = nfl) data.frame( Term = names(coef(fit)), Estimate = coef(fit), p = summary(fit)$coefficients[, 4] ) |> gt() |> fmt_number(Estimate, decimals = 4) |> gt_significance(Estimate, p) |> gt_theme_booktabs(accent = "#1A3E6F")
Term Estimate
(Intercept) 0.6899***
points_for 0.0015***
points_against −0.0020***
*** p < 0.01, ** p < 0.05, * p < 0.1