Skip to main content

group

group() 

Groups one or more elements together. This element acts as a scope, all state changes such as transformations and styling only affect the elements in the group. Elements after the group are not affected by the changes inside the group.

// Create group
group({
stroke(5pt)
scale(.5); rotate(45deg)
rect((-1,-1),(1,1))
})
rect((-1,-1),(1,1))

Elements to group together. A least one is required. A function that accepts ctx and returns elements is also accepted.

anchor:

none or str
Default: none

Anchor to position the group and it's children relative to. For translation the difference between the groups "default" anchor and the passed anchor is used.

Styling

Root: group

padding:

Default: none

How much padding to add around the group's bounding box. none applies no padding. A number applies padding to all sides equally. A dictionary applies padding following Typst's pad function: https://typst.app/docs/reference/layout/pad/. An array follows CSS like padding: (y, x), (top, x, bottom) or (top, right, bottom, left).

Anchors

Supports border and path anchors of the axis aligned bounding box of all the child elements of the group.

You can add custom named anchors to the group by using the anchor element while in the scope of said group, see anchor for more details.

The default anchor is "center" but this can be overridden by using anchor to place a new anchor called "default".

When using named elements within a group, you can access the element's anchors outside of the group by using the implicit anchor coordinate. e.g. "a.b.north"

group(name: "a", {
circle((), name: "b")
})
circle("a.b.south", radius: 0.2)
circle((name: "a", anchor: "b.north"), radius: 0.2)