gt-extras
  • Intro
  • API Reference
  1. Colors
  2. gt_highlight_cols
  • 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. Colors
  2. gt_highlight_cols

gt_highlight_cols

gt_highlight_cols(
    gt,
    columns=None,
    fill='#80bcd8',
    alpha=None,
    font_weight='normal',
    font_color='#000000',
    include_column_labels=False,
)

Add color highlighting to one or more specific columns.

The gt_highlight_cols() function takes an existing GT object and adds highlighting color to the cell background of a specific column(s).

Parameters

gt : GT

An existing GT object.

columns : SelectExpr = None

The columns to target. Can be a single column or a list of columns (by name or index). If None, the coloring is applied to all columns.

fill : str = '#80bcd8'

A string indicating the fill color. If nothing is provided, then "#80bcd8" (light blue) will be used as a default.

alpha : float | None = None

A float [0, 1] for the alpha transparency value for the color as single value in the range of 0 (fully transparent) to 1 (fully opaque). If not provided the fill color will either be fully opaque or use alpha information from the color value if it is supplied in the "#RRGGBBAA" format.

font_weight : Literal['normal', 'bold', 'bolder', 'lighter'] | int = 'normal'

A string or number indicating the weight of the font. Can be a text-based keyword such as "normal", "bold", "lighter", "bolder", or, a numeric value between 1 and 1000, inclusive. Note that only variable fonts may support the numeric mapping of weight.

font_color : str = '#000000'

A string indicating the text color. If nothing is provided, then "#000000" (black) will be used as a default.

include_column_labels : bool = False

Whether to also highlight column labels of the assigned columns.

Returns

: GT

The GT object is returned. This is the same object that the method is called on so that we can facilitate method chaining.

Examples

from great_tables import GT, md
from great_tables.data import gtcars
import gt_extras as gte

gtcars_mini = gtcars[["model", "year", "hp", "trq"]].head(8)

gt = (
    GT(gtcars_mini, rowname_col="model")
    .tab_stubhead(label=md("*Car*"))
)

gt.pipe(gte.gt_highlight_cols, columns="hp")
Car year hp trq
GT 2017 647.0 550.0
458 Speciale 2015 597.0 398.0
458 Spider 2015 562.0 398.0
458 Italia 2014 562.0 398.0
488 GTB 2016 661.0 561.0
California 2015 553.0 557.0
GTC4Lusso 2017 680.0 514.0
FF 2015 652.0 504.0
gt_data_color_by_group
gt_highlight_rows