margin

Plot-margin specification: padding on each side of the plot canvas.

Each side accepts a Typst length (e.g., 1cm, 8pt) or auto to fall through to the renderer’s dynamic default (which leaves room for the axis title, tick labels, and any legend). Defaults to auto on every side so calling margin() with no arguments resets to the dynamic default, and margin(left: 2cm) overrides only the left side. Pass the result to theme under the plot-margin key.

Usage

margin(
  top: auto,
  right: auto,
  bottom: auto,
  left: auto,
)

Parameters

Parameter Default Description
top auto Top margin (Typst length or auto).
right auto Right margin.
bottom auto Bottom margin.
left auto Left margin.

Returns

Margin dictionary consumed by theme.

Examples

Wide left margin to give a long axis title room to breathe; other sides keep the renderer’s default.

#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(plot-margin: margin(left: 2cm, top: 0.5cm)),
  width: 10cm,
  height: 6cm,
)

Scatter plot of y against x with a widened 2cm left plot margin and a slightly taller top margin via the margin record.

Scatter plot of y against x with a widened 2cm left plot margin and a slightly taller top margin via the margin record.

Pin every side to zero for an edge-to-edge canvas.

#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(plot-margin: margin(top: 0pt, right: 0pt, bottom: 0pt, left: 0pt)),
  width: 10cm,
  height: 6cm,
)

Scatter plot of y against x with all four plot margins pinned to zero so the chart fills the canvas edge to edge.

Scatter plot of y against x with all four plot margins pinned to zero so the chart fills the canvas edge to edge.

See also

theme.

Back to top