The cell_borders()
helper function is to be used with the tab_style()
function, which itself allows for the setting of custom styles to one or more
cells. Specifically, the call to cell_borders()
should be bound to the
styles
argument of tab_style()
. The selection
argument is where we
define which borders should be modified (e.g., "left"
, "right"
, etc.).
With that selection, the color
, style
, and weight
of the selected
borders can then be modified.
Usage
cell_borders(sides = "all", color = "#000000", style = "solid", weight = px(1))
Arguments
- sides
The border sides to be modified. Options include
"left"
,"right"
,"top"
, and"bottom"
. For all borders surrounding the selected cells, we can use the"all"
option.- color, style, weight
The border color, style, and weight. The
color
can be defined with a color name or with a hexadecimal color code. The defaultcolor
value is"#000000"
(black). Thestyle
can be one of either"solid"
(the default),"dashed"
,"dotted"
, or"hidden"
. Theweight
of the border lines is to be given in pixel values (thepx()
helper function is useful for this. The default value forweight
is"1px"
. Borders for any definedsides
can be removed by supplyingNULL
to any ofcolor
,style
, orweight
.
Examples
Add horizontal border lines for all table body rows in exibble
using
tab_style()
and cell_borders()
.
exibble %>%
gt() %>%
tab_options(row.striping.include_table_body = FALSE) %>%
tab_style(
style = cell_borders(
sides = c("top", "bottom"),
color = "red",
weight = px(1.5),
style = "solid"
),
locations = cells_body(
columns = everything(),
rows = everything()
)
)
Incorporate different horizontal and vertical borders at several locations.
This uses multiple cell_borders()
and cells_body()
calls within
list()
s.
exibble %>%
gt() %>%
tab_style(
style = list(
cell_borders(
sides = c("top", "bottom"),
color = "#FF0000",
weight = px(2)
),
cell_borders(
sides = c("left", "right"),
color = "#0000FF",
weight = px(2)
)
),
locations = list(
cells_body(
columns = num,
rows = is.na(num)
),
cells_body(
columns = currency,
rows = is.na(currency)
)
)
)
See also
Other helper functions:
adjust_luminance()
,
cell_fill()
,
cell_text()
,
cells_body()
,
cells_column_labels()
,
cells_column_spanners()
,
cells_footnotes()
,
cells_grand_summary()
,
cells_row_groups()
,
cells_source_notes()
,
cells_stub_grand_summary()
,
cells_stub_summary()
,
cells_stubhead()
,
cells_stub()
,
cells_summary()
,
cells_title()
,
currency()
,
default_fonts()
,
escape_latex()
,
google_font()
,
gt_latex_dependencies()
,
html()
,
md()
,
pct()
,
px()
,
random_id()
,
stub()