Graphviz (using dot) seems to insist on removing leading white space in labels. This makes it unnecessarily tricky to position node labels that go outside the node using xlabel. Using the Nodes Alignment example form here Dot for Petri Nets - ML Wiki, adding xlabel to the nodes, like: p2 [xlabel="p2"];
I get the following:
If I try to pad with leading whitespace in the hope of getting the label better aligned, like p2 [xlabel=" p2"];
I get the same result, as above.
If I pad the label with leading underscores: p2 [xlabel="____p2"];
I get something closer to what I want:
But of course, I do not want the underscores, I want white space.
How can I achieve that?
Thanks.
// MVHMF
Good idea, thanks.
Using three nbsp moves the label a little bit to the right, but not enough. And using more than three nbsp either does not move the label at all from the original (white space stripped) position, or puts it way off.
I also tried to input UTF-8 non-breaking space into the label string, but that gave the same result as nbsp in HTML string.
I have tried with two versions of Graphviz. One is the Graphviz Online which apparently uses Graphviz version 2.40.1 (20161225.0304). The other is the graphviz LaTeX package to generate graphs for a LaTeX document in Overleaf. That package was last update 2013, so probably also there an older version of Graphviz is used, though it is unclear to me how to find out which.
So maybe those versions are too old to matter.
But even when I try in in a command window using Graphviz 8.0.1 with the command dot -Tpng G.dot
I still do not get the leading spaces, and the p2 label is placed over an arrow as shown above. And it does not matter if I use svg or jpg as output.
This is on W10, graphviz version 8.0.1 (20230327.1645). On this particular computer I get from the dot -v G.dot output related to font info: "fontname: “Times-Roman” resolved to: (ps:pango Times New Roman, ) (PangoCairoWin32Font) “Times New Roman, 19.9990234375"”