Info
This site is generated using the static site generator developed by the Typst Community. Please adjust the text content of this banner according to your usage requirements. At Typst GmbH's request, when publishing documentation, you must clearly indicate that it is non-official and display the version of Typst being documented. For details, refer to Issue #874 on typst/typst.
TypstDocumentEnglish
v0.dev.2025-09-12

polygon
Element
Element
Element functions can be customized with set and show rules.

A closed polygon.

The polygon is defined by its corner points and is closed automatically.

Example

#polygon(
  fill: blue.lighten(80%),
  stroke: blue,
  (20%, 0pt),
  (60%, 0pt),
  (80%, 2cm),
  (0%,  2cm),
)
Preview

Parameter
Parameter
Parameters are input values for functions. Specify them in parentheses after the function name.

fill
Settable
Settable
Settable parameters can be set using the set rule, changing the default value used thereafter.

How to fill the polygon.

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

Default value:

none

fill-rule
Settable
Settable
Settable parameters can be set using the set rule, changing the default value used thereafter.

The drawing rule used to fill the polygon.

See the curve documentation for an example.

Available string values:
  • non-zero

    Specifies that "inside" is computed by a non-zero sum of signed edge crossings.

  • even-odd

    Specifies that "inside" is computed by an odd number of edge crossings.

Default value:

"non-zero"

stroke
Settable
Settable
Settable parameters can be set using the set rule, changing the default value used thereafter.

How to stroke the polygon.

Can be set to none to disable the stroke or to auto for a stroke of 1pt black if and only if no fill is given.

Default value:

auto

vertices
Required
Required
Required parameters must be specified when calling the function.
Positional
Positional
Positional parameters can be set by specifying them in order, omitting the parameter name.
Variadic
Variadic
Variadic parameters can be specified multiple times.

The vertices of the polygon. Each point is specified as an array of two relative lengths.

Definition
Definition
These functions and types can have related definitions. To access a definition, specify the name of the function or type, followed by the definition name separated by a period.

regular

A regular polygon, defined by its size and number of vertices.

Show example
#polygon.regular(
  fill: blue.lighten(80%),
  stroke: blue,
  size: 30pt,
  vertices: 3,
)
Preview

fill

How to fill the polygon. See the general polygon's documentation for more details.

stroke

How to stroke the polygon. See the general polygon's documentation for more details.

size

The diameter of the circumcircle of the regular polygon.

Default value:

1em

vertices

The number of vertices in the polygon.

Default value:

3

Open official docs

Search