cell_borders() is to be used with tab_style(), 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 sides 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
Border sides
vector<character>// default:"all"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
Border color
scalar<character>|NULL// default:"#000000"The border
colorcan be defined with a color name or with a hexadecimal color code. The defaultcolorvalue is"#000000"(black). Borders for any definedsidescan be removed by supplyingNULLhere.- style
Border line style
scalar<character>|NULL// default:"solid"The border
stylecan be one of either"solid"(the default),"dashed","dotted","hidden", or"double". Borders for any definedsidescan be removed by supplyingNULLhere.- weight
Border weight
scalar<character>|NULL// default:px(1)The default value for
weightis"1px"and higher values will become more visually prominent. Borders for any definedsidescan be removed by supplyingNULLto any ofcolor,style, orweight.
Examples
We can add horizontal border lines for all table body rows in a gt table
based on the exibble dataset. For this, we need to use tab_style()
(targeting all cells in the table body with cells_body()) in conjunction
with cell_borders() in the style argument. Both top and bottom borders
will be added as "solid" and "red" lines with a line width of 1.5 px.
exibble |>
gt() |>
tab_style(
style = cell_borders(
sides = c("top", "bottom"),
color = "red",
weight = px(1.5),
style = "solid"
),
locations = cells_body()
)
It's possible to incorporate different horizontal and vertical ("left" and
"right") borders at several different locations. This uses multiple
cell_borders() and cells_body() calls within their own respective lists.
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(),
currency(),
default_fonts(),
escape_latex(),
from_column(),
google_font(),
gt_latex_dependencies(),
html(),
latex(),
md(),
nanoplot_options(),
pct(),
px(),
random_id(),
row_group(),
stub(),
system_fonts(),
unit_conversion()