Apply a theme to the table and choose its color mode.
GT.opt_theme(
theme=None,
mode=None,
)
The opt_theme() method stores a Theme and a color mode on the table. The theme gives the table its colors, fonts and other options, and can hold a separate set of colors for dark mode through its dark= argument. The mode picks which colors are used: "light" always uses the light colors, "dark" always uses the dark colors, and "auto" (the default) follows the viewer’s preference.
Parameters
theme: Theme | None = None
-
The Theme to apply. If None, the theme already on the table is left as it is.
mode: ThemeMode | None = None
-
The color mode, one of
"auto", "light" or "dark". If None, the mode already on the table is left as it is.
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
Using select columns from the exibble dataset, let’s create a table and choose its color mode with opt_theme().
from great_tables import GT, Theme, exibble
gt_tbl = GT(exibble[["num", "char", "currency", "row"]], rowname_col="row")
gt_tbl.opt_theme(mode="dark")
|
num |
char |
currency |
| 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 |
| row_5 |
5550.0 |
None |
1325.81 |
| row_6 |
None |
fig |
13.255 |
| row_7 |
777000.0 |
grapefruit |
None |
| row_8 |
8880000.0 |
honeydew |
0.44 |
A custom Theme sets the tokens and options that should differ from the defaults.
gt_tbl.opt_theme(Theme(border="#9AA5B1", font="Georgia", data_row_padding=4))
|
num |
char |
currency |
| 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 |
| row_5 |
5550.0 |
None |
1325.81 |
| row_6 |
None |
fig |
13.255 |
| row_7 |
777000.0 |
grapefruit |
None |
| row_8 |
8880000.0 |
honeydew |
0.44 |
Use the dark= argument of Theme to give the table its own colors in dark mode.
gt_tbl.opt_theme(
Theme(border="#9AA5B1", dark=Theme(background="#101418", border="#2A3038")),
mode="dark",
)
|
num |
char |
currency |
| 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 |
| row_5 |
5550.0 |
None |
1325.81 |
| row_6 |
None |
fig |
13.255 |
| row_7 |
777000.0 |
grapefruit |
None |
| row_8 |
8880000.0 |
honeydew |
0.44 |