Skip to contents

Draws borders between every column and every row of a gt table, giving it a full grid, with an option to extend the borders around the column and row labels.

Usage

gt_border_grid(gt_object, color = "black", weight = 1, include_labels = FALSE)

Arguments

gt_object

A gt table object to modify.

color

Character. The border color. Defaults to "black".

weight

Numeric. The border thickness in pixels. Defaults to 1.

include_labels

Logical. Should the borders extend around the row and column labels? Defaults to FALSE.

Value

Returns a modified gt table with the grid borders applied.

Details

Column borders are drawn as right cell borders on every column but the last, and the row borders are added as scoped CSS on the .gt_row top border. A table id is resolved or generated first, since that CSS is keyed on #<table_id>.

Examples

library(gt)

afc_south <- subset(
  sdv_example_standings, division == "AFC South",
  c(team_name, wins:points_against)
)
gt(afc_south) |> gt_border_grid()
team_name wins losses ties win_pct points_for points_against
Jacksonville Jaguars 13 4 0 0.765 474 336
Houston Texans 12 5 0 0.706 404 295
Indianapolis Colts 8 9 0 0.471 466 412
Tennessee Titans 3 14 0 0.176 284 478
# heavier gray lines, including around the labels pacific <- subset( sdv_example_standings, division == "Pacific", c(team_name, wins, losses, win_pct:points_against) ) gt(pacific) |> gt_border_grid(color = "#BBBBBB", weight = 2, include_labels = TRUE)
team_name wins losses win_pct points_for points_against
Los Angeles Lakers 53 29 0.646 9540 9396
Phoenix Suns 45 37 0.549 9232 9112
LA Clippers 42 40 0.512 9329 9236
Golden State Warriors 37 45 0.451 9398 9444
Sacramento Kings 22 60 0.268 9102 9922