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.

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 default color value is "#000000" (black). The style can be one of either "solid" (the default), "dashed", or "dotted". The weight of the border lines is to be given in pixel values (the px() helper function is useful for this. The default value for weight is "1px". Borders for any defined sides can be removed by supplying NULL to any of color, style, or weight.

See also

Other helper functions: cell_fill(), cell_text(), cells_styles(), escape_latex(), gt_latex_dependencies(), html(), md(), pct(), px(), random_id()

Examples

# Add horizontal border lines for # all table body rows in `exibble` tab_1 <- exibble %>% gt() %>% tab_options(row.striping.include_table_body = FALSE) %>% tab_style( style = cell_borders( sides = c("top", "bottom"), color = "gray", weight = px(0.5), style = "solid" ), locations = cells_data( columns = everything(), rows = everything() ) ) # Incorporate different horizontal and # vertical borders at several locations; # this uses multiple `cell_borders()` and # `cells_data()` calls within `list()`s tab_2 <- exibble %>% gt() %>% tab_style( style = list( cell_borders( sides = c("top", "bottom"), color = "red", weight = px(2) ), cell_borders( sides = c("left", "right"), color = "blue", weight = px(2) ) ), locations = list( cells_data( columns = vars(num), rows = is.na(num) ), cells_data( columns = vars(currency), rows = is.na(currency) ) ) )