element-text
Text element: font size, weight, colour, and angle.
Pass the result to theme under keys like axis-text, axis-title, legend-text, or legend-title.
Usage
element-text(
size: none,
weight: none,
colour: none,
angle: none,
family: none,
margin: none,
)Parameters
| Parameter | Default | Description |
|---|---|---|
size |
none |
Text size (a Typst length), or none to inherit. |
weight |
none |
Font weight (e.g., "regular", "bold"), or none to inherit. |
colour |
none |
Text colour, or none to inherit. |
angle |
none |
Rotation angle (a Typst angle), or none to inherit. |
family |
none |
Font family (e.g., "sans", "serif"), or none to inherit. |
margin |
none |
Per-side spacing built with margin. Each side accepts a Typst length (absolute or relative); em is preferred so spacing scales with the surface font size. Sides left at auto fall through to the renderer default. none keeps every side at the default. |
Returns
Element dictionary consumed by theme.
Examples
Bigger axis-title font passed via theme.
#let d = range(0, 10).map(i => (x: i, y: i * 0.5))
#plot(
data: d,
mapping: aes(x: "x", y: "y"),
layers: (geom-point(size: 2pt),),
theme: theme(axis-title: element-text(size: 14pt)),
width: 10cm,
height: 6cm,
)Combine multiple text fields and a rotation angle on axis tick labels.
#let d = (
(q: "Q1", y: 3), (q: "Q2", y: 5), (q: "Q3", y: 4), (q: "Q4", y: 6),
)
#plot(
data: d,
mapping: aes(x: "q", y: "y"),
layers: (geom-col(),),
theme: theme(axis-text: element-text(
size: 9pt,
angle: 30deg,
colour: rgb("#1f77b4"),
)),
width: 10cm,
height: 6cm,
)Widen the gap between the axis tick labels and the axis title using a relative margin that tracks the title font size.
#let d = range(0, 10).map(i => (x: i, y: i * 0.5))
#plot(
data: d,
mapping: aes(x: "x", y: "y"),
layers: (geom-point(size: 2pt),),
theme: theme(axis-title: element-text(
size: 11pt,
margin: margin(top: 1.6em, right: 1.6em),
)),
width: 10cm,
height: 6cm,
)See also
theme, element-line, element-rect, element-blank, element-typst, margin.