Skip to content

Commit

Permalink
Add example to docs of tab_style()
Browse files Browse the repository at this point in the history
  • Loading branch information
rich-iannone committed Dec 14, 2023
1 parent 43d5be1 commit 15f124e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions great_tables/_tab_create_modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,35 @@ def tab_style(
)
```
Let's use `exibble` once again to create a simple, two-column output table (keeping only the
`num` and `currency` columns). With the `tab_style()` method (called twice), we'll add style to
the values already formatted by `fmt_number()` and `fmt_currency()`. In the `style` argument of
each `tab_style()` call, we can define multiple types of styling with the `style.fill()` and
`style.text()` classes (enclosing these in a list). The cells to be targeted for styling require
the use of `loc.body()`, which is used here with different columns being targeted.
```{python}
(
gt.GT(exibble[["num", "currency"]])
.fmt_number(columns = "num", decimals=1)
.fmt_currency(columns = "currency")
.tab_style(
style=[
style.fill(color="lightcyan"),
style.text(weight="bold")
],
locations=loc.body(columns="num")
)
.tab_style(
style=[
style.fill(color = "#F9E3D6"),
style.text(style = "italic")
],
locations=loc.body(columns="currency")
)
)
```
Returns
-------
GT
Expand Down

0 comments on commit 15f124e

Please sign in to comment.