gt-extras
  • Intro
  • API Reference
  1. Utilities
  2. gt_add_divider
  • API Reference
  • Plotting
    • gt_plt_bar
    • gt_plt_bar_pct
    • gt_plt_bar_stack
    • gt_plt_conf_int
    • gt_plt_dot
    • gt_plt_dumbbell
    • gt_plt_winloss
  • Colors
    • gt_color_box
    • gt_data_color_by_group
    • gt_highlight_cols
    • gt_highlight_rows
    • gt_hulk_col_numeric
  • Themes
    • gt_theme_538
    • gt_theme_dark
    • gt_theme_dot_matrix
    • gt_theme_espn
    • gt_theme_excel
    • gt_theme_guardian
    • gt_theme_nytimes
    • gt_theme_pff
  • Icons and Images
    • add_text_img
    • fa_icon_repeat
    • gt_fa_rank_change
    • gt_fa_rating
    • img_header
  • Utilities
    • fmt_pct_extra
    • gt_add_divider
    • gt_duplicate_column
    • gt_merge_stack
    • gt_two_column_layout
    • with_hyperlink
    • with_tooltip

On this page

  • Parameters
  • Returns
  • Examples
  1. Utilities
  2. gt_add_divider

gt_add_divider

gt_add_divider(
    gt,
    columns,
    sides='right',
    color='grey',
    divider_style='solid',
    weight=2,
    include_labels=True,
)

Add dividers to specified columns in a GT object.

The gt_add_divider() function takes an existing GT object and adds dividers to the specified columns. Dividers can be applied to one or more sides of the cells, with customizable color, style, and weight. Optionally, dividers can also be applied to column labels.

Parameters

gt : GT

A GT object to modify.

columns : SelectExpr

The columns to which dividers should be applied.

sides : Literal['right', 'left', 'top', 'bottom', 'all'] | list[Literal['right', 'left', 'top', 'bottom', 'all']] = 'right'

The sides of the cells where dividers should be added. Options include "right", "left", "top", "bottom", or "all". A list of sides can also be provided to apply dividers to multiple sides.

color : str = 'grey'

The color of the dividers.

divider_style : Literal['solid', 'dashed', 'dotted', 'hidden', 'double'] = 'solid'

The style of the dividers. Options include "solid", "dashed", "dotted", "hidden", and "double".

weight : int = 2

The thickness of the dividers in pixels.

include_labels : bool = True

Whether to include dividers in the column labels. If True, dividers will be applied to both the body and the column labels. If False, dividers will only be applied to the body.

Returns

: GT

A GT object with dividers added to the specified columns.

Examples

import pandas as pd
from great_tables import GT
from great_tables.data import peeps
import gt_extras as gte

peeps_mini = peeps.head(6)

gt = (
    GT(peeps_mini)
    .cols_hide([
        "name_family", "postcode", "country", "country_code",
        "dob", "gender", "state_prov", "email_addr",
    ])
    .tab_spanner("Location", ["address", "city"])
    .tab_spanner("Body Measurements", ["height_cm", "weight_kg"])
)

gt.pipe(
    gte.gt_add_divider,
    columns="name_given",
    color="#FFB90F",
    divider_style="double",
    weight=8,
).pipe(
    gte.gt_add_divider,
    columns="phone_number",
    color="purple",
    sides=["right", "left"],
    weight=5,
)
name_given Location phone_number Body Measurements
address city height_cm weight_kg
Ruth 4299 Bobcat Drive Baileys Crossroads 240-783-7630 153 76.4
Peter 3705 Hidden Pond Road Red Boiling Springs 615-699-3517 175 74.9
Fanette 4200 Swick Hill Street New Orleans 985-205-2970 167 61.6
Judyta 2287 Cherry Ridge Drive Oakfield 585-948-7790 156 54.5
Leonard 1496 Hillhaven Drive Los Angeles 323-857-6576 177 113.2
Maymun 4088 Barnes Avenue Hamilton 513-738-1936 172 88.4
fmt_pct_extra
gt_duplicate_column