great_tables
  • Get Started
  • Examples
  • Reference
  • Blog
  1. Table Structure
  2. Header and Footer
  • Intro
  • Overview
  • Table Structure
    • Header and Footer
    • Stub (Row Labels)
    • Column Labels
  • Format
    • Formatting Values
    • Nanoplots
  • Style
    • Styling the Table Body
    • Styling the whole table
    • Colorizing with Data
  • Theming
    • Table Theme Options
    • Premade Themes
  • Selecting table parts
    • Column Selection
    • Row Selection
    • Location selection
  • Extra
    • Contributing Guidelines
  1. Table Structure
  2. Header and Footer

Header and Footer

The way that we add components like the Table Header and source notes in the Table Footer is to use the tab_*() family of methods. A Table Header is easy to add so let’s see how the previous table looks with a title and a subtitle. We can add this component using the tab_header() method:

from great_tables import GT, md, html
from great_tables.data import islands

islands_mini = islands.head(10)

# Make a display table with the `islands_tbl` table;
# put a heading just above the column labels
(
    GT(islands_mini)
    .tab_header(
        title = "Large Landmasses of the World",
        subtitle = "The top ten largest are presented"
    )
)
Large Landmasses of the World
The top ten largest are presented
name size
Africa 11506
Antarctica 5500
Asia 16988
Australia 2968
Axel Heiberg 16
Baffin 184
Banks 23
Borneo 280
Britain 84
Celebes 73

The Header table component provides an opportunity to describe the data that’s presented. Using subtitle= allows us to insert a subtitle, which is an optional part of the Header. We may also style the title= and subtitle= using Markdown! We do this by wrapping the values passed to title= or subtitle= with the md() helper function (we may also use html() in a similar fashion). Here is an example with the table data truncated for brevity:

# Make a display table with the `islands_tbl` table;
# put a heading just above the column labels
gt_tbl = (
    GT(islands.head(2))
    .tab_header(
        title = md("Large Landmasses of the *World* 🌐"),
        subtitle = md("The top **ten** largest are presented")
    )
)

gt_tbl
Large Landmasses of the World 🌐
The top ten largest are presented
name size
Africa 11506
Antarctica 5500

A source note can be added to the table’s Footer through use of the tab_source_note() method. It works in the same way as tab_header() (it also allows for Markdown inputs) except it can be called multiple times—each invocation results in the addition of a source note.

# Display the `islands_tbl` data with a heading and two source notes
(
    gt_tbl
    .tab_source_note(
        source_note = "Source: The World Almanac and Book of Facts, 1975, page 406."
    )
    .tab_source_note(
        source_note = md("Reference: McNeil, D. R. (1977) *Interactive Data Analysis*. Wiley.")
    )
)
Large Landmasses of the World 🌐
The top ten largest are presented
name size
Africa 11506
Antarctica 5500
Source: The World Almanac and Book of Facts, 1975, page 406.
Reference: McNeil, D. R. (1977) Interactive Data Analysis. Wiley.
Overview
Stub (Row Labels)