How to not remove leading white space in label...?

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:

image

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:

image

But of course, I do not want the underscores, I want white space.
How can I achieve that?
Thanks.
// MVHMF

A bit of a dubious solution, but you can use an HTML-like label: p2 [xlabel=<&nbsp;&nbsp;&nbsp;p2>]

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.

Anyway, thanks for the attempt to help.
// MVHMF

Huh, I am seeing leading spaces (see below). So:

  • What version of Graphviz are you using (type dot -V)
  • What OS are you using?
  • What result do you see on your screen when you run dot -v myfile.gv >junk (I am looking for font information)
digraph G {
  rankdir=LR;
  subgraph place {
    node [shape=circle,fixedsize=true,label="",height=.3,width=.3];
    i [label="&bull;", fontsize=20];
    o; p1;
    p2 [xlabel="    p2"];    // was p2;
  }
  subgraph transitions {
    node [shape=rect,height=0.4,width=.4];
    a; b; c; d; e; f;
  }

  # align horizontally
  {edge [weight=2]; i->a->p1; p2->f->o;}

  p1->c->p2;
  p2->d->p1;
  i->e->p2;
  p1->b->o; 
  # align vertically
  {rank=same; b;c;d;e;}  
}

Giving:
leadingSpaces1

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"”

Thanks
// MVHMF

Huh again.
Works on my Linux system, but not Windows and not Javascript.

Is this

  • a “font problem” (see Font FAQ | Graphviz)
  • an OS bug? (you seem to using Windows)
  • none of the above?

I didn’t find anything similar in the Issues database (Issues · graphviz / graphviz · GitLab). I suggest you create an Issue.