TypstDocumentation

rectShowable
Question mark

A rectangle with optional content.

Example

// Without content.
#rect(width: 35%, height: 30pt)

// With content.
#rect[
  Automatically sized \
  to fit the content.
]
Preview

Parameters
Question mark

body
contentPositional
Question mark

The content to place into the rectangle.

When this is omitted, the rectangle takes on a default size of at most 45pt by 30pt.

width

The rectangle's width, relative to its parent container.

height

The rectangle's height, relative to its parent container.

fill
nonecolorSettable
Question mark

How to fill the rectangle.

When setting a fill, the default stroke disappears. To create a rectangle with both fill and stroke, you have to configure both.

#rect(fill: blue)
Preview

stroke
noneautolengthcolordictionarystrokeSettable
Question mark

How to stroke the rectangle. This can be:

#stack(
  dir: ltr,
  spacing: 1fr,
  rect(stroke: red),
  rect(stroke: 2pt),
  rect(stroke: 2pt + red),
)
Preview

radius
relative lengthdictionarySettable
Question mark

How much to round the rectangle's corners, relative to the minimum of the width and height divided by two. This can be:

#set rect(stroke: 4pt)
#rect(
  radius: (
    left: 5pt,
    top-right: 20pt,
    bottom-right: 10pt,
  ),
  stroke: (
    left: red,
    top: yellow,
    right: green,
    bottom: blue,
  ),
)
Preview

inset
relative lengthdictionarySettable
Question mark

How much to pad the rectangle's content.

The default value is 5pt.

Note: When the rectangle contains text, its exact size depends on the current text edges.

A #rect(inset: 0pt)[tight] fit.
Preview

outset
relative lengthdictionarySettable
Question mark

How much to expand the rectangle's size without affecting the layout.

This is, for instance, useful to prevent an inline rectangle from affecting line layout. For a generalized version of the example below, see the documentation for the raw text's block parameter.

This
#rect(
  fill: luma(235),
  inset: (x: 3pt, y: 0pt),
  outset: (y: 3pt),
  radius: 2pt,
)[rectangle]
is inline.
Preview