gt-extras
  • Get Started
  • API Reference
  1. Colors
  2. gt_highlight_cols
  • API Reference
  • Plotting
    • gt_plt_bar
    • gt_plt_dot
    • gt_plt_conf_int
  • Colors
    • gt_highlight_cols
    • gt_hulk_col_numeric
    • gt_color_box
  • Themes
    • gt_theme_538
    • gt_theme_espn
    • gt_theme_guardian
    • gt_theme_nytimes
    • gt_theme_excel
    • gt_theme_dot_matrix
    • gt_theme_dark
    • gt_theme_pff
  • Icons and Images
    • fa_icon_repeat
    • gt_fa_rating
  • HTML Helpers
    • gt_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',
)

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 either be a single column name or a series of column names provided in a list. If None, the alignment 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 : int | None = None

An integer [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.

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_plt_conf_int
gt_hulk_col_numeric