# Edge label placement

**URL:** <https://forum.graphviz.org/t/edge-label-placement/3338>\
**Category:** Help\
**Created:** [May 5, 2026, 10:13am UTC](https://forum.graphviz.org/t/edge-label-placement/3338 "2026-05-05T10:13:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yanncha](https://avatars.discourse-cdn.com/v4/letter/y/f9ae1b/32.png) [@Yanncha](https://forum.graphviz.org/u/Yanncha)\
**Post date:** [May 5, 2026, 10:13am UTC](https://forum.graphviz.org/t/edge-label-placement/3338/1 "2026-05-05T10:13:57Z")

</div>

Hello (and greetings to the forum as it’s my first post),

I started to tinker last week with Graphviz and I find the language quite clear (though the documentation is not always straightforward).

In a graph I’d like to create a “Caption” subgraph, as partially shown below.

[dot verbose=true]

```auto
digraph test {
  label="Caption"

  {
    rank="same"
    B,C,D
  }
  A → B[label=“A\ndepends\non B”]
  B → C[label=“Unordered\nconstraint”, dir=“both”, arrowhead=“onormal”, arrowtail=“onormal”, style=“dashed”]
  A → C → D[color=“red”]
  D → A[label=“Def. loop”, color=“red”]
}

```

[/dot]

For clarity, is it possible to move the A → B label outwards (i.e. to the left) ?

Cheers !

Yann

---

<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:** [May 5, 2026, 2:17pm UTC](https://forum.graphviz.org/t/edge-label-placement/3338/2 "2026-05-05T14:17:08Z")

</div>

Welcome.  
Graphviz is indeed complex. Here are my _go to’s_ for documentation:

- [https://www.graphviz.org/pdf/dotguide.pdf](https://www.graphviz.org/pdf/dotguide.pdf)
- [Documentation | Graphviz](https://www.graphviz.org/documentation/) (especially: [Attributes | Graphviz](https://www.graphviz.org/doc/info/attrs.html))
- [https://www.graphviz.org/documentation/TSE93.pdf](https://www.graphviz.org/documentation/TSE93.pdf)

Here is a proposed fix to your label issue: change that one **label** to an **xlabel** ([xlabel | Graphviz](https://www.graphviz.org/docs/attrs/xlabel/)). It seems to satisfy your request.

```auto
digraph test {
  label="Caption"

  {
    rank="same"
    B,C,D
  }
  A -> B[xlabel="A\ndepends\non B"] // changed label to xlabel
  B -> C[label="Unordered\nconstraint", dir="both", arrowhead="onormal", arrowtail="onormal", style="dashed"]
  A -> C -> D[color="red"]
  D -> A[label="Def. loop", color="red"]
}

```

Giving:

 ![forum33381](https://global.discourse-cdn.com/graphviz/original/2X/5/594fe46ebe3895166503baf2ae6b5ad1d666d81a.png)

---

<div class="post-metadata">

**Author:** ![Yanncha](https://avatars.discourse-cdn.com/v4/letter/y/f9ae1b/32.png) [@Yanncha](https://forum.graphviz.org/u/Yanncha)\
**Post date:** [May 5, 2026, 4:22pm UTC](https://forum.graphviz.org/t/edge-label-placement/3338/3 "2026-05-05T16:22:13Z")

</div>

Thanks for your help and the documents!

I missed xlabel, this is indeed useful. However, it becomes messier if I use it with `concentrate=true`:

[dot, verbose=true]

```auto
digraph test {
  label=“Caption”
  concentrate=true

  {
    rank=“same”
    B,C,D
  }
  A → B[xlabel=“A\ndepends\non B”] // changed label to xlabel
  B → C[label=“Unordered\nconstraint”, dir=“both”, arrowhead=“onormal”, arrowtail=“onormal”, style=“dashed”]
  A → C → D[color=“red”]
  D → A[label=“Def. loop”, color=“red”]
  B -> D[label="Requirement", style="bold", color="forestgreen"]
}

```

[/dot]

Same question applies to the example above. Is it possible to move the “Requirement” upwards or tweak the position manually?

I tried to fiddle with xlp and related attributes but it doesn’t seem to help.

---

<div class="post-metadata">

**Author:** ![Yanncha](https://avatars.discourse-cdn.com/v4/letter/y/f9ae1b/32.png) [@Yanncha](https://forum.graphviz.org/u/Yanncha)\
**Post date:** [May 5, 2026, 4:29pm UTC](https://forum.graphviz.org/t/edge-label-placement/3338/4 "2026-05-05T16:29:37Z")

</div>

Ok, I found a workaround that gives a satisfactory result, by manually specifying some ports:

[dot verbose=true]

```auto
digraph test {
  label="Caption"
  concentrate=true
  {
    rank="same"
    B,C,D
  }
  // Added explicit ports on some nodes
  A:n -> B[label="A\ndepends\non B"]
  B -> C[label="Unordered\nconstraint", dir="both", arrowhead="onormal", arrowtail="onormal", style="dashed"]
  A:nw -> C[color="red"]
  C:n -> D:n[color="red"]
  D -> A[label="Def. loop", color="red"]
  B -> D[label="Requirement", style="bold", color="forestgreen"]
}

```

[\dot]

(btw I don’t know why the graph isn’t rendered, hence the multiple tries/edits/post deletions, sorry)

---

<div class="post-metadata">

**Author:** ![Yanncha](https://avatars.discourse-cdn.com/v4/letter/y/f9ae1b/32.png) [@Yanncha](https://forum.graphviz.org/u/Yanncha)\
**Post date:** [May 7, 2026, 9:28am UTC](https://forum.graphviz.org/t/edge-label-placement/3338/6 "2026-05-07T09:28:46Z")

</div>

Ok, for whatever reason, the graph is not rendering the same way it was when I posted the message…

First, the nodes on 1st line were ordered : C B D (I was happily surprised by this graphviz proposal)

Thus the green arrow was a straight one, and the A-\>B label was less ambiguous as the D-\>A label is already on the far right.

But now the nodes are ordered B C D again, which is quite messier with specified ports… Did I miss something ?

---

<div class="post-metadata">

**Author:** ![Yanncha](https://avatars.discourse-cdn.com/v4/letter/y/f9ae1b/32.png) [@Yanncha](https://forum.graphviz.org/u/Yanncha)\
**Post date:** [May 7, 2026, 9:43am UTC](https://forum.graphviz.org/t/edge-label-placement/3338/7 "2026-05-07T09:43:12Z")

</div>

For now I corrected it by working on the C → B connexion, which changes the rank and improves the restult. But I don’t think I changed it before, which is strange.

Here’s the current code:

[dot, verbose=true]

```auto
digraph test {
  label=“Caption”
  concentrate=true

  {
    rank=“same”
    B,C,D
  }

  A:n → B[label=“A\ndepends\non B”]
  C → B[label=“Unordered\nconstraint”, dir=“both”, arrowhead=“onormal”, arrowtail=“onormal”, style=“dashed”]
  A:nw → C[color=“red”]
  C:n → D:n[color=“red”]
  D → A[label=“Def. loop”, color=“red”]
  B → D[label=“Requirement”, style=“bold”, color=“forestgreen”]
}

```

[/dot]

Also in my memory the C → D arrow I was getting in my previous result was curvier, avoiding the C → B label. Is there a way to correct this ?

Thanks !

Yann

PS : I think I know now why my previous graph is not rendered on the forum, possibly due to the comment. But I can’t edit anymore.

---

<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:** [May 7, 2026, 7:14pm UTC](https://forum.graphviz.org/t/edge-label-placement/3338/8 "2026-05-07T19:14:58Z")

</div>

Here is a (maybe) fix to make the edge “curvier”. But note that **dot** produces unsatisfactory results for many variations on this theme.

```auto
digraph test {
  label="Caption"
  concentrate=true

  {
    rank="same"
    B,C,D
  }

  A:n -> B[label="A\ndepends\non B"]
  C -> B[label="Unordered\nconstraint", dir="both", arrowhead="onormal", arrowtail="onormal", style="dashed"]
  A:nw -> C[color="red"]
  C:ne -> D:nw [color=red label=" "] // trying to make the visible version "curvier"
  C:n-> D:n [color="invis"]
  D -> A[label="Def. loop", color="red"]
  B -> D[label="Requirement", style="bold", color="forestgreen"]
}

```

Giving:

 ![forum3338B1](https://global.discourse-cdn.com/graphviz/original/2X/2/29360315339e7091189d53252a40b737c9f05d6e.png)

Here are three forum entries about edges & edge labels. With luck, they should help you place your edges and labels more to your liking.

- [Fun with edges!](https://forum.graphviz.org/t/fun-with-edges/888)
- [A program to "fix" simple edges](https://forum.graphviz.org/t/a-program-to-fix-simple-edges/1792)
- [Fun with Edge Labels!](https://forum.graphviz.org/t/fun-with-edge-labels/1643)
