Great Tables exposes options to customize the appearance of tables via two methods:
tab_style - targeted styles (e.g. color a specific cell of data).
tab_options - broad styles (e.g. color the header and source notes).
Both methods target parts of the table, as shown in the diagram below.
This page covers how to style and theme your table using GT.tab_options(), which is meant to quickly set a broad range of styles. In the future, even more granular options will become available via GT.tab_style().
We’ll use the basic GT object below for most examples, since it marks some of the table parts.
As the graph above showed, tables are made of many parts—such as the heading, column labels, and 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.
In order to define the vertical lines between cells, set vline styles. For example, the code below makes both horizontal and vertical lines between cells solid.
Based on the sections above, we can design an overall theme for a table.
This requires setting a decent number of options, but makes a big difference when presenting a table! Below is a table with a simple, blue theme. (The code is hidden by default, but can be expanded to see all the options set).
Code
from great_tables import GT, exibble# TODO: are there names we can give the three colors?# e.g. primary = "#0076BA", etc..(GT(exibble, rowname_col="row", groupname_col="group") .tab_header("THE HEADING", "(a subtitle)") .tab_stubhead("THE STUBHEAD") .tab_source_note("THE SOURCE NOTE") .tab_options(# table ---- table_border_top_color="#004D80", table_border_bottom_color="#004D80",# heading ---- heading_border_bottom_color="#0076BA",# column labels ---- column_labels_border_top_color="#0076BA", column_labels_border_bottom_color="#0076BA", column_labels_background_color="#FFFFFF",# row group ---- row_group_border_top_color="#0076BA", row_group_border_bottom_color="#0076BA",# stub ---- stub_background_color="#0076BA", stub_border_style="solid", stub_border_color="#0076BA",# table body ---- table_body_border_top_color="#0076BA", table_body_border_bottom_color="#0076BA", table_body_hlines_style="none", table_body_vlines_style="none",# misc ----#row_striping_background_color="#F4F4F4" ))