Style API¶
Styles define how selected table cells are rendered. Use them with
TypTable.tab_style and a locator from typ_tables.locators:
from narwhals import selectors as ncs
from typ_tables import TypTable, locators, style
table = (
TypTable(df)
.tab_style(
locator=locators.LocBody(columns=ncs.numeric()),
text=style.TextStyle(weight="bold"),
cell=style.CellStyle(align="right"),
)
)
TextStyle controls the content inside a cell, such as font size, weight, and
text fill. CellStyle controls the table cell container, such as alignment,
inset, background fill, and borders. Sides is a helper for properties that can
vary by side, such as cell inset or stroke.
Style values are written as Typst-compatible strings and are passed through to
the generated Typst. For body and stub locators, style fields can also be lists
or Narwhals expressions so each row can resolve to a different value. For
single-region locators, such as LocHeader and LocStubhead, style fields must
be scalar values.
Styling Types¶
typ_tables.ttypes.Alignment
module-attribute
¶
Typst alignment keyword for table cell content.
typ_tables.ttypes.Relative
module-attribute
¶
Typst relative length value.
Use a Typst-compatible string such as "10pt", "1em", or "20%".
typ_tables.style.Fill
module-attribute
¶
Typst fill value.
Use any Typst-compatible paint string, such as "red" or "#f2f2f2".
typ_tables.style.Length
module-attribute
¶
Typst length value.
Use a Typst-compatible string such as "10pt", "1em", or "0.2cm".
typ_tables.style.Stroke
module-attribute
¶
Typst stroke value.
Use any Typst-compatible stroke string, such as "1pt + black".
typ_tables.style.FontStyle
module-attribute
¶
Typst font style keyword.
typ_tables.style.FontWeight
module-attribute
¶
FontWeight = (
Literal[
"thin",
"extralight",
"light",
"regular",
"medium",
"semibold",
"bold",
"extrabold",
"black",
]
| int
)
Typst font weight keyword or numeric font weight.
typ_tables.style.Sides
dataclass
¶
Bases: Generic[T]
Describe per-side values for Typst cell properties.
Use this helper for properties that can vary by side, such as inset and
stroke. Only fields with non-None values are emitted to Typst.
typ_tables.style.Inset
module-attribute
¶
typ_tables.style.FullStroke
module-attribute
¶
Style Containers¶
typ_tables.style.TextStyle
dataclass
¶
Text-level style properties for selected table cells.
These fields map to Typst text(...) arguments. Values are written as Typst
strings, except for fractions, which is rendered as a boolean. Scalar
values apply the same style everywhere the locator selects. Lists and
Narwhals expressions resolve one value per data row for row-based locators.
font
class-attribute
instance-attribute
¶
Font family name.
weight
class-attribute
instance-attribute
¶
Font FontWeight.
stretch
class-attribute
instance-attribute
¶
Font stretch value.
stroke
class-attribute
instance-attribute
¶
Text FullStroke.
fractions
class-attribute
instance-attribute
¶
Whether Typst should render numeric fractions specially.
typ_tables.style.CellStyle
dataclass
¶
Cell-level style properties for selected table cells.
These fields map to Typst table.cell(...) arguments. Scalar values apply
the same style everywhere the locator selects. Lists and Narwhals
expressions resolve one value per data row for row-based locators.