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

**URL:** <https://forum.graphviz.org/t/how-to-not-remove-leading-white-space-in-label/1782>\
**Category:** Help\
**Created:** [September 11, 2023, 9:21am UTC](https://forum.graphviz.org/t/how-to-not-remove-leading-white-space-in-label/1782 "2023-09-11T09:21:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabian](https://avatars.discourse-cdn.com/v4/letter/f/f6c823/32.png) [@fabian](https://forum.graphviz.org/u/fabian)\
**Post date:** [September 11, 2023, 9:21am UTC](https://forum.graphviz.org/t/how-to-not-remove-leading-white-space-in-label/1782/1 "2023-09-11T09:21:34Z")

</div>

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](http://mlwiki.org/index.php/Dot_for_Petri_Nets), adding xlabel to the nodes, like:  
`p2 [xlabel="p2"];`  
I get the following:

![image](https://global.discourse-cdn.com/graphviz/original/2X/c/c1cfee1eb383d7009d786d27a8e40daec2bd0704.png)

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](https://global.discourse-cdn.com/graphviz/original/2X/e/ef24f77d3cc3c41ae67ffefa917d4d436724bf34.png)

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

---

<div class="post-metadata">

**Author:** ![smattr](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/smattr/32/85_2.png) [@smattr](https://forum.graphviz.org/u/smattr)\
**Post date:** [September 11, 2023, 10:53am UTC](https://forum.graphviz.org/t/how-to-not-remove-leading-white-space-in-label/1782/2 "2023-09-11T10:53:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fabian](https://avatars.discourse-cdn.com/v4/letter/f/f6c823/32.png) [@fabian](https://forum.graphviz.org/u/fabian)\
**Post date:** [September 11, 2023, 11:58am UTC](https://forum.graphviz.org/t/how-to-not-remove-leading-white-space-in-label/1782/3 "2023-09-11T11:58:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [September 11, 2023, 6:22pm UTC](https://forum.graphviz.org/t/how-to-not-remove-leading-white-space-in-label/1782/4 "2023-09-11T18:22:59Z")

</div>

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)

```auto
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](https://global.discourse-cdn.com/graphviz/original/2X/0/037b5dc37a55ea373fa760c271d269119c8edd7b.png)

---

<div class="post-metadata">

**Author:** ![fabian](https://avatars.discourse-cdn.com/v4/letter/f/f6c823/32.png) [@fabian](https://forum.graphviz.org/u/fabian)\
**Post date:** [September 11, 2023, 7:26pm UTC](https://forum.graphviz.org/t/how-to-not-remove-leading-white-space-in-label/1782/5 "2023-09-11T19:26:00Z")

</div>

I have tried with two versions of Graphviz. One is the [Graphviz Online](https://dreampuf.github.io/GraphvizOnline/) which apparently uses Graphviz version 2.40.1 (20161225.0304). The other is the [graphviz LaTeX package](https://ctan.org/pkg/graphviz) 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

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [September 12, 2023, 12:07am UTC](https://forum.graphviz.org/t/how-to-not-remove-leading-white-space-in-label/1782/6 "2023-09-12T00:07:19Z")

</div>

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

Is this

- a “font problem” (see [Font FAQ | Graphviz](https://www.graphviz.org/faq/font/))
- 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](https://gitlab.com/graphviz/graphviz/-/issues)). I suggest you create an Issue.
