merlin
April 22, 2026, 1:17pm
1
I am having trouble to define a style for content boxes.
In the code snippet below I want to display a blue rectangle box next to the white circle.
My goal is to define a style that I can than reuse multiple times such that I dont have to type it over and over again. I can not figure out how to do this. Maybe you can point me in the right direction?
#import "@preview/cetz:0.5.0"
#cetz.canvas({
import cetz.draw: *
content((0,0),[$x=5$],frame:"circle",padding:2pt,fill:white)
let agent_style = (frame:"rect",padding:2pt,fill:blue)
content((5,0),[$z=9$],style:agent_style)
})
Almost! Have a look at this:
#cetz.canvas({
import cetz.draw: *
content((0, 0), [$x=5$], frame: "circle", padding: 2pt, fill: white)
// option 1: spread style arguments
let agent_style = (frame: "rect", padding: 2pt, fill: blue)
content((5, 0), [$z=9$], ..agent_style)
// option 2: set default style for content
set-style(content: (frame: "rect", padding: 2pt, fill: red))
content((7, 0), [$z=9$])
group({
// set-style is scoped: it only applies to the current group
set-style(content: (frame: "rect", padding: 2pt, fill: orange))
content((9, 0), [$z=9$])
})
})
merlin
April 22, 2026, 2:42pm
3
Thank you very much, for these options. The first option is what I was looking for.
Now though, I would like to have rounded corners in that style, too. I thought I could make this happen as described here:
https://cetz-package.github.io/docs/api/draw-functions/shapes/rect
But it seems like this doesnt work in the definition of my agent_style.
Do you have a solution for that, too?
I have tried this:
// imports
#import "@preview/cetz:0.5.0"
#cetz.canvas({
import cetz.draw: *
let agent_style = (frame:"rect",padding:2pt,fill:blue,radius:10%)
content((0,0),[$x=5$],frame:"circle",padding:2pt,fill:white)
content((5,0),[$z=9$],..agent_style)
})
It is not throwing an error, but it is not rounding the corners either.