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 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:
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. However they are created based on the axis aligned bounding box of all the child elements of the group.
You can add custom anchors to the group by using the anchor
element while in the scope of said group, see anchor
for more details. You can also copy over anchors from named child element by using the copy-anchors
element as they are not accessible from outside the group.
The default anchor is "center" but this can be overridden by using anchor
to place a new anchor called "default".
Named elements within a group can also be accessed as string anchors, see Coordinate Anchors.