-
Hi, I am trying to draw a Hasse Diagram using Typst, but I can't find any info in the documentation about drawing nodes. I tried drawing a circle but I have no idea how to add a text next to it in the graphic, I am a little lost, any guidance will be super helpful! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
We don't really have nodes in CeTZ, just elements and their anchors. You could try using the You can place content using the
About drawing custom diagrams though I don't know of a way to draw a line from the edge of one node at an arbitrary angle to another (this is espcially difficult if you want to use custom node shapes like rectangles with rounded corners). So I would recommend drawing the connections then the lines on top:
|
Beta Was this translation helpful? Give feedback.
-
Thanks @fenjalien, with your guidance I was able to get an idea how to achieve it, so far with simple diagrams (they can get sort of complex), but for now I am only trying to figure out a proper placement of labels before trying to optimize this and create a package to draw them. So far I am doing something like this: #canvas({
import draw: *
let a = (1, 0)
let c = (2, 0)
let e = (3, 0)
let b = (2, 1)
let f = (1, 2)
let d = (2, 2)
let g = (2, 3)
set-style(circle: (radius: 0.1, fill: black), content: (padding: .1))
circle(a, name: "a")
content("a.bottom", [a], anchor: "top")
circle(c, name: "c")
content("c.bottom", [c], anchor: "top")
circle(e, name: "e")
content("e.bottom", [e], anchor: "top")
circle(b, name: "b")
content("b.left", [b], anchor: "right")
circle(f, name: "f")
content("f.left", [f], anchor: "right")
circle(d, name: "d")
content("d.right", [d], anchor: "left")
circle(g, name: "g")
content("g.right", [g], anchor: "left")
line(c, b)
line(e, b)
line(a, f)
line(b, f)
line(b, d)
line(d, g)
line(f, g)
}) I started using Typst very recently (a few weeks ago) so I am still trying to figure out a few things while I go :) so I accept any suggestion or feedback. |
Beta Was this translation helpful? Give feedback.
We don't really have nodes in CeTZ, just elements and their anchors. You could try using the
tree
library (see section 6.1 in the manual) for your diagram but at a glance Hasse Diagrams are cyclical and use multiple inheritance which I'm pretty sure isn't supported (@johannes-wolf?).You can place content using the
content
element (3.3.8) and place them next to other elements by using anchors (2.2):About drawing custom diagrams though I don't know of a way to draw a line fro…