Skip to main content

Table Options

When you need to change how a whole part of the table looks (all of the column labels, the heading, the lines between body rows), tab_options() is the right tool. Rather than styling individual cells or specific locations, this method lets you set colors, fonts, borders, and spacing for entire table parts in a single call. This page explains the structure of option names, demonstrates how to style different parts, and covers the opt_*() methods, which are shortcuts for common sets of options.

A useful way to think about the relationship between tab_options() and tab_style(): use tab_options() when you want to set broad defaults for entire table parts (e.g., “all column labels should have this background color”). Use tab_style() when you need to target specific cells, columns, or rows. The two work together naturally: tab_options() sets the base look, and tab_style() applies targeted overrides on top of it. Both methods target parts of the table, as shown in the diagram below.

A diagram of the parts of a table: the Table Header, the Stub and Stub Head, the Column Labels, the Table Body, and the Table Footer.

We’ll use the basic GT object below for most examples, since it marks some of the table parts.

import polars as pl
from great_tables import GT, data

lil_exibble = data.pl.exibble.head(5).select("num", "char", "currency", "row", "group")

gt_ex = (
    GT(lil_exibble, rowname_col="row", groupname_col="group")
    .tab_header("THE HEADING", "(a subtitle)")
    .tab_stubhead("THE STUBHEAD")
    .tab_source_note("THE SOURCE NOTE")
    .grand_summary_rows(fns={"GRAND SUMMARY ROW": pl.col("num", "currency").sum()})
)

gt_ex
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE

Table Option Parts

As the diagram above showed, tables are made of many parts. These include the heading, column labels, and the stub. tab_options() organizes options based on table part.

The code below illustrates the table parts tab_options() can target, by setting the background color for various parts.

(
    gt_ex
    .tab_options(
        container_width="100%",
        table_background_color="lightblue",
        heading_background_color="gold",
        column_labels_background_color="aquamarine",
        row_group_background_color="lightyellow",
        stub_background_color="lightgreen",
        source_notes_background_color="#f1e2af",
        grand_summary_row_background_color="lightpink",
    )
)
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE

Notice two important pieces:

  • The argument heading_background_color="gold" sets the heading part’s background to gold.
  • Parts like container and table are the broadest. They cover all the other parts of the table.

Finding Options: Part, Type, Attribute

Option names in tab_options() follow a consistent naming convention. Understanding the pattern makes it easy to find the exact option you need without searching through documentation. The format is:

{part name}_{type}_{attribute}

For example, the option row_group_border_top_color has these pieces:

  • part: row_group
  • type: border_top
  • attribute: color
Note

Here are the parts supported in tab_options():

There are also quarto and ihtml options, which control Quarto integration and interactive tables rather than a visible table part.

Styling Borders

Many table parts support customizing border colors and style. This is shown below for column labels.

gt_ex.tab_options(
    column_labels_border_top_color="blue",
    column_labels_border_top_style="solid",
    column_labels_border_top_width="5px"
)
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE

The column labels section now has a thick blue border on top. Each border option follows the same triplet of color, style, and width attributes, which you can combine to create the exact look you want.

Styling Background Color

gt_ex.tab_options(
    heading_background_color="purple"
)
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE

The heading area (title and subtitle) is now purple. Background color options are available for every table part, letting you assign a distinct visual identity to each region.

Styling Body Cells

The table body can style the lines between individual cells. Use the hlines and vlines option types to specify cell line color, style, and width.

For example, the code below changes horizontal lines (hlines) between cells to be red, dashed lines.

gt_ex.tab_options(
    table_body_hlines_color="red",
    table_body_hlines_style="dashed",
    table_body_hlines_width="4px",
)
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE

In order to define the vertical lines between cells, set vlines styles. For example, the code below makes both horizontal and vertical lines between cells solid.

gt_ex.tab_options(
    table_body_hlines_style="solid",
    table_body_vlines_style="solid",
)
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE

With both hlines and vlines set to solid, the table body displays a classic grid appearance. Setting either to "none" removes those lines entirely for a cleaner, minimal look.

Set Options Across Table Parts

Some options starting with table_ apply to all parts of the table. For example, fonts and background color apply everywhere.

gt_ex.tab_options(
    table_background_color="green",
    table_font_color="darkblue",
    table_font_style="italic",
    table_font_names="Times New Roman"
)
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE

Options set across the whole table can be overridden by styling a specific part.

gt_ex.tab_options(
    table_background_color="orange",
    heading_background_color="pink"
)
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE

The orange background applies everywhere except the heading, which overrides it with pink. This layered approach means you can set sensible table-wide defaults and then customize individual parts as needed.

opt_*() Shortcuts

Some looks take several options at once. The opt_*() methods set those options for you from a single call, so you don’t need to remember the option names. Each one is a shortcut for tab_options(), and what it sets can still be changed with tab_options() directly.

Align the Table Header

The title and subtitle are centered by default. opt_align_table_header() sets the heading_align option, taking align="left", "center", or "right".

gt_ex.opt_align_table_header(align="left")
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE

A left-aligned heading works well for tables embedded in text-heavy documents, where it lines up with the text around it.

Make Text ALL CAPS

opt_all_caps() makes the labels of the table uppercase, in a smaller, bolder font. It sets the font size, weight, and text transform options of the column labels, the stub, and the row group labels, and its locations= can limit it to some of them (loc.column_labels, loc.stub, or loc.row_groups).

gt_ex.opt_all_caps()
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE

Uppercase labels set the structure of the table apart from its values, giving it a more formal appearance.

Reduce or Expand Padding

Two methods scale the padding of the heading, column labels, row group labels, body rows, and source notes: opt_vertical_padding() for the space above and below the text, and opt_horizontal_padding() for the space at its sides. Their scale= goes from 0 to 3, where 1 keeps the default padding. Here is a table with less vertical padding.

gt_ex.opt_vertical_padding(scale=0.3)
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE

Reducing vertical padding creates a more compact table that fits more data into less vertical space. Increasing the horizontal padding does the opposite across the table.

gt_ex.opt_horizontal_padding(scale=3)
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE

The extra room between columns improves readability when columns contain long values.

Set a Table Outline

By default, a table has borders above and below it but none at its sides. opt_table_outline() draws a border on all four sides, setting the style, width, and color of each of the table_border_* options.

gt_ex.opt_table_outline()
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE

The outline’s style=, width=, and color= can all be changed from their defaults (a solid, 3px, light gray line).

Stripe the Rows

opt_row_striping() turns on the row_striping_include_table_body option, which gives every other body row a background color (set with row_striping_background_color).

gt_ex.opt_row_striping()
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE

Alternating row backgrounds help the eye follow a row across a wide table.

Set the Table Font

opt_table_font() sets the font of the whole table through the table_font_names option, with weight= and style= setting its weight and style. Here it uses one of the themed font stacks.

gt_ex.opt_table_font(stack="humanist")
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE

The font= argument takes one or more font names (or a Google Font via google_font()), and stack= takes the name of one of fifteen themed font stacks, like "humanist" or "monospace-code", which the next section shows. Fonts given with font= go ahead of the current ones, unless add=False replaces them (a stack= always replaces them).

Themed Font Stacks

A font stack is a list of fonts in order of preference: the browser shows the text in the first font of the list that the reader’s device has. So a stack doesn’t give every reader the same font. It gives them the same kind of font, since each of the fifteen stacks lists fonts of one style that come with macOS, Windows, Linux, and Android, and ends with a generic family like serif that every browser has. The stacks come from the Modern Font Stacks project, which has pictures of each stack as drawn on each system. system_fonts() gives the fonts of a stack as a list.

The On This Device column of the table below has a sample of each stack. Your browser draws the samples with the fonts on your device, so they look different on another system, and under each sample is the name of the font that your browser chose (a small script on this page finds it). The other columns name the font that each system usually chooses. Each sample gets its font from a hidden column, through from_column().

Show the code
from great_tables import from_column, loc, md, style, system_fonts

stack_rows = [
    # kind, stack, macOS, Windows, Linux
    ("Sans Serif", "system-ui", "San Francisco", "Segoe UI", "Cantarell or Ubuntu"),
    ("Sans Serif", "humanist", "Seravek", "Calibri", "Ubuntu or DejaVu Sans"),
    ("Sans Serif", "geometric-humanist", "Avenir", "Corbel", "URW Gothic"),
    ("Sans Serif", "classical-humanist", "Optima", "Candara", "Noto Sans"),
    ("Sans Serif", "neo-grotesque", "Helvetica Neue", "Arial", "Roboto or Nimbus Sans"),
    ("Sans Serif", "industrial", "DIN Alternate", "Bahnschrift", "Nimbus Sans Narrow"),
    ("Sans Serif", "rounded-sans", "Hiragino Maru Gothic", "Calibri", "Quicksand or Comfortaa"),
    ("Serif", "transitional", "Charter", "Sitka Text", "Bitstream Charter"),
    ("Serif", "old-style", "Iowan Old Style", "Palatino Linotype", "URW Palladio L or P052"),
    ("Serif", "slab-serif", "Rockwell", "Sitka Small", "DejaVu Serif"),
    ("Serif", "antique", "Superclarendon", "Georgia", "URW Bookman"),
    ("Serif", "didone", "Didot", "Sylfaen", "Noto Serif Display"),
    ("Monospace", "monospace-slab-serif", "Courier New", "Courier New", "Nimbus Mono PS"),
    ("Monospace", "monospace-code", "Menlo", "Cascadia Code or Consolas", "DejaVu Sans Mono"),
    ("Handwritten", "handwritten", "Bradley Hand", "Segoe Print", "Chilanka"),
]


def css_font_family(stack):
    # Quote the font names that have spaces, as CSS needs
    return ", ".join(f"'{font}'" if " " in font else font for font in system_fonts(stack))


def sample(font_family):
    # The sample text, over an element that the script on this page fills in with the font in use
    return f'Sales: $1,284.50<br><small class="font-used" data-fonts="{font_family}">–</small>'


stacks = (
    pl.DataFrame(stack_rows, schema=["kind", "stack", "macos", "windows", "linux"], orient="row")
    .with_columns(family=pl.col("stack").map_elements(css_font_family, return_dtype=pl.String))
    .select("kind", "stack", pl.col("family").alias("sample"), "macos", "windows", "linux", "family")
)

(
    GT(stacks, rowname_col="stack", groupname_col="kind", id="font-stacks")
    .cols_hide(columns="family")
    .fmt(sample, columns="sample")
    .tab_style(
        style=style.text(font=from_column(column="family"), size="1.1em", whitespace="nowrap"),
        locations=loc.body(columns="sample"),
    )
    .tab_style(
        style=style.text(font="monospace", size="0.9em", whitespace="nowrap"),
        locations=loc.stub(),
    )
    .tab_spanner(label="Usually Shown On", columns=["macos", "windows", "linux"])
    .cols_label(
        sample="On This Device",
        macos="macOS",
        windows="Windows",
        linux="Linux",
    )
    .tab_footnote(
        footnote=md("Safari uses SF Mono and SF Pro Rounded, through `ui-monospace` and `ui-rounded`."),
        locations=loc.body(columns="macos", rows=["monospace-code", "rounded-sans"]),
    )
    .tab_footnote(
        footnote=(
            "With Microsoft Office installed, Windows uses an earlier font of the stack: "
            "Arial Rounded MT, Rockwell, Bookman Old Style, or Bodoni MT."
        ),
        locations=loc.body(
            columns="windows", rows=["rounded-sans", "slab-serif", "antique", "didone"]
        ),
    )
    .tab_source_note("Linux fonts vary with the distribution and the fonts installed.")
)
On This Device Usually Shown On
macOS Windows Linux
Sans Serif
system-ui Sales: $1,284.50
–
San Francisco Segoe UI Cantarell or Ubuntu
humanist Sales: $1,284.50
–
Seravek Calibri Ubuntu or DejaVu Sans
geometric-humanist Sales: $1,284.50
–
Avenir Corbel URW Gothic
classical-humanist Sales: $1,284.50
–
Optima Candara Noto Sans
neo-grotesque Sales: $1,284.50
–
Helvetica Neue Arial Roboto or Nimbus Sans
industrial Sales: $1,284.50
–
DIN Alternate Bahnschrift Nimbus Sans Narrow
rounded-sans Sales: $1,284.50
–
Hiragino Maru Gothic1 Calibri2 Quicksand or Comfortaa
Serif
transitional Sales: $1,284.50
–
Charter Sitka Text Bitstream Charter
old-style Sales: $1,284.50
–
Iowan Old Style Palatino Linotype URW Palladio L or P052
slab-serif Sales: $1,284.50
–
Rockwell Sitka Small2 DejaVu Serif
antique Sales: $1,284.50
–
Superclarendon Georgia2 URW Bookman
didone Sales: $1,284.50
–
Didot Sylfaen2 Noto Serif Display
Monospace
monospace-slab-serif Sales: $1,284.50
–
Courier New Courier New Nimbus Mono PS
monospace-code Sales: $1,284.50
–
Menlo1 Cascadia Code or Consolas DejaVu Sans Mono
Handwritten
handwritten Sales: $1,284.50
–
Bradley Hand Segoe Print Chilanka
1 Safari uses SF Mono and SF Pro Rounded, through ui-monospace and ui-rounded.
2 With Microsoft Office installed, Windows uses an earlier font of the stack: Arial Rounded MT, Rockwell, Bookman Old Style, or Bodoni MT.
Linux fonts vary with the distribution and the fonts installed.

Each Stack in a Table

The stacks are grouped by kind below. Open a group, and then a stack, to see the example table in that stack. Opening a stack closes the one that was open, so you can go through a group one stack at a time.

Sans-serif stacks
System UI: system-ui

The font of the device’s own interface: San Francisco on macOS, Segoe UI on Windows, and Roboto on Android. It is easy to read at small sizes and comes in many weights, and it is close to the default fonts of a table.

gt_ex.opt_table_font(stack="system-ui")
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE
Humanist: humanist

Sans-serif letters with shapes that come from handwriting, and a little contrast between thick and thin strokes, as in Gill Sans. They are warm and very readable.

gt_ex.opt_table_font(stack="humanist")
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE
Geometric Humanist: geometric-humanist

Letters drawn from circles and straight lines, as in Futura and Avenir, with enough variation to read easily. They look clean and modern.

gt_ex.opt_table_font(stack="geometric-humanist")
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE
Classical Humanist: classical-humanist

Strokes that widen toward their ends without serifs, after the letters carved in Roman stone, as in Optima. They look graceful and a little formal.

gt_ex.opt_table_font(stack="classical-humanist")
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE
Neo-Grotesque: neo-grotesque

The plain, even sans serif of Helvetica and Arial. It stays out of the way of the data, so it suits almost any table.

gt_ex.opt_table_font(stack="neo-grotesque")
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE
Industrial: industrial

Squared, sturdy letters like those of road signs and engineering drawings, as in DIN. They give a table a technical look.

gt_ex.opt_table_font(stack="industrial")
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE
Rounded Sans: rounded-sans

Sans-serif letters with rounded ends, which look soft and friendly. They suit casual tables.

gt_ex.opt_table_font(stack="rounded-sans")
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE
Serif stacks
Transitional: transitional

Serif letters with more contrast and a more upright stress than old style, as in Times New Roman and Charter. They are a good serif for reading.

gt_ex.opt_table_font(stack="transitional")
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE
Old Style: old-style

The serif letters of the Renaissance, with diagonal stress and little contrast between thick and thin strokes, as in Garamond and Palatino. They have a warm, bookish look.

gt_ex.opt_table_font(stack="old-style")
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE
Slab Serif: slab-serif

Heavy, block-like serifs that meet the strokes without a curve, as in Rockwell. They look bold and sturdy.

gt_ex.opt_table_font(stack="slab-serif")
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE
Antique: antique

Sturdy 19th-century serif letters with thick serifs that curve into the strokes, as in Clarendon and Bookman. They recall old posters and newspapers.

gt_ex.opt_table_font(stack="antique")
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE
Didone: didone

Strong contrast between thick strokes and hairline serifs, with vertical stress, as in Didot and Bodoni. They look elegant, and are best at larger sizes.

gt_ex.opt_table_font(stack="didone")
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE
Monospace and handwritten stacks
Monospace Slab Serif: monospace-slab-serif

Letters of one fixed width with slab serifs, like those of a typewriter, as in Courier. Every character takes the same space.

gt_ex.opt_table_font(stack="monospace-slab-serif")
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE
Monospace Code: monospace-code

Fixed-width fonts made for programming, as in Menlo and Consolas, with shapes that keep characters like 0 and O, or 1 and l, apart.

gt_ex.opt_table_font(stack="monospace-code")
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE
Handwritten: handwritten

Casual letters that look written by hand. They are best kept for informal tables.

gt_ex.opt_table_font(stack="handwritten")
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE

Adding Your Own CSS

When the option you need doesn’t exist, opt_css() lets you add your own CSS rules to the table. Give the table an ID with with_id() (or GT(id=...)), and begin each rule’s selector with that ID: the rules then apply to that table alone, and not to the other tables on the page.

The rules below do two things that no option does. Body rows are highlighted while the pointer is over them (try it on the table), with a translucent blue that shows on light and dark pages alike. And the body cells use digits of equal width (tabular figures), so that numbers with the same number of digits line up exactly from row to row.

(
    gt_ex
    .with_id("hover-demo")
    .opt_css(
        css="""
        #hover-demo .gt_table_body tr:hover .gt_row {
          background-color: rgba(0, 118, 186, 0.15);
        }
        #hover-demo .gt_table_body .gt_row {
          font-variant-numeric: tabular-nums;
        }
        """
    )
)
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE

The rules use the class names that Great Tables gives to the parts of the table, like gt_table_body for the body and gt_row for its cells. Each opt_css() call adds to the CSS of earlier ones; add=False replaces it instead.

When a function makes many tables for the same page, each needs an ID of its own. The random_id() helper makes one from random letters (10 by default), which can then be used in the rules.

from great_tables import random_id

table_id = random_id()

(
    gt_ex
    .with_id(table_id)
    .opt_css(css=f"#{table_id} .gt_table_body .gt_row {{ font-variant-numeric: tabular-nums; }}")
)
THE HEADING
(a subtitle)
THE STUBHEAD num char currency
grp_a
row_1 0.1111 apricot 49.95
row_2 2.222 banana 17.95
row_3 33.33 coconut 1.39
row_4 444.4 durian 65100.0
grp_b
row_5 5550.0 None 1325.81
GRAND SUMMARY ROW 6030.0631 --- 66495.1
THE SOURCE NOTE

With tab_options() and the opt_*() methods, you can define the visual identity of a table at a broad level. The structured naming convention makes it straightforward to find and set the options you need, and opt_css() covers what the options don’t.

Options set this way belong to one table. To give many tables the same look, put the options in a Theme and apply it with opt_theme(), or start from one of the premade looks of opt_stylize(). The next page, Themes, covers both.