Skip to contents

A restrained dark theme. The background is a near-black instead of pure black, which avoids the smearing pure black causes on OLED screens. Column labels sit on a slightly raised band, rules are hairlines, and the body has no fills.

Usage

gt_theme_midnight(
  gt_object,
  accent = "#5B8DEF",
  density = c("comfortable", "compact", "social"),
  ...
)

Arguments

gt_object

A gt table object to modify.

accent

Character. A hex color for the row-group labels and the rule above the table. Defaults to "#5B8DEF".

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

Light text on a dark background reads as lighter weight than it is, so the theme opens up the line height to compensate.

Color scales on dark grounds

A green-to-red ramp built for white paper goes muddy on a near-black background, as its mid-tones collapse toward the background. Use pal_midnight with gt_color_ranks() instead.

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 midnight theme

See also

pal_midnight for a color scale that survives a dark ground, and gt_theme_terminal() for a denser dark look.

Examples

library(gt)
nfc_west <- subset(
  sdv_example_standings, division == "NFC West",
  c(team_name, wins:points_against)
)
gt(nfc_west) |> gt_theme_midnight()
team_name wins losses ties win_pct points_for points_against
Seattle Seahawks 14 3 0 0.824 483 292
Los Angeles Rams 12 5 0 0.706 518 346
San Francisco 49ers 12 5 0 0.706 437 371
Arizona Cardinals 3 14 0 0.176 355 488
# color scales need lifting on a dark ground; see pal_midnight west <- subset( sdv_example_standings, league == "nba" & conference == "Western", c(team_name, wins, losses, win_pct) ) gt(west) |> gt_theme_midnight() |> gt_color_ranks(win_pct, palette = pal_midnight)
team_name wins losses win_pct
Oklahoma City Thunder 64 18 0.780
Denver Nuggets 54 28 0.659
Minnesota Timberwolves 49 33 0.598
Portland Trail Blazers 42 40 0.512
Utah Jazz 22 60 0.268
Los Angeles Lakers 53 29 0.646
Phoenix Suns 45 37 0.549
LA Clippers 42 40 0.512
Golden State Warriors 37 45 0.451
Sacramento Kings 22 60 0.268
San Antonio Spurs 62 20 0.756
Houston Rockets 52 30 0.634
New Orleans Pelicans 26 56 0.317
Dallas Mavericks 26 56 0.317
Memphis Grizzlies 25 57 0.305