format-wrap

Soft-wrap a long string by inserting a newline at word boundaries.

Usage

format-wrap(
  width: 20,
)

Parameters

Parameter Default Description
width 20 Maximum line width in characters.

Returns

A closure value => string.

Examples

Soft-wrap long discrete tick labels onto multiple lines at a width of eight characters.

#let d = (
  (g: "alpha quadrant", y: 4),
  (g: "beta sector", y: 7),
  (g: "gamma frontier", y: 3),
)
#plot(
  data: d,
  mapping: aes(x: "g", y: "y"),
  layers: (geom-col(),),
  scales: (scale-x-discrete(labels: format-wrap(width: 8)),),
  width: 10cm,
  height: 6cm,
)

Bar chart of three groups whose long discrete x-axis tick labels are soft-wrapped at width 8 onto two lines each via format-wrap.

Bar chart of three groups whose long discrete x-axis tick labels are soft-wrapped at width 8 onto two lines each via format-wrap.

See also

format-title, label-wrap.

Back to top