How can I align two (disconnected) nodes in GraphViz?

Viewed 106

Suppose I have the GraphViz graph:

digraph G {
a->b->d;
c->d;
}

How can I make a and c be aligned vertically, i.e. appear at the same height?

enter image description here

1 Answers

You can align them using grouping and a group-scope attribute:

digraph G {
{rank = same; a; c;}
a->b->d;
c->d;
}

enter image description here

Note that if your rankdir value is different, this alignment will not be vertical: e.g. if rankdir=LR then a and c will be horizontally aligned to the same position - with the arrows pointing rightwards.

Related