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

gt_highlight_rows

gt_highlight_rows(
    gt,
    rows=None,
    fill='#80bcd8',
    alpha=None,
    font_weight='normal',
    font_color='#000000',
    include_row_labels=False,
)

Add color highlighting to one or more specific rows.

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

Parameters

gt : GT

An existing GT object.

rows : RowSelectExpr = None

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

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_row_labels : bool = False

Whether to also highlight row labels of the assigned rows.

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_rows, rows=[2, 7])
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_highlight_cols
gt_hulk_col_numeric