Align nodes of subgraph with another subgraph nodes

How do I align nodes with each other between subgraphs?
In the example, I would like all the 0 nodes aligned vertically as well as the 1, 2, 3 and 4 nodes. It would be good if all the right edges of subgraphs were extended as necessary to align too.

![From this

To this

digraph AlignWhenMissing {
rankdir=LR;
node [shape=box]

subgraph clusterA {label = "A Shift a4 along (no a3)";
    a0 -> a1;
    a1 -> a2;
    a2 -> a4;
}

subgraph clusterB {label = "B Shift b2 above a2";
    b0 -> b2;
    b2 -> b3;
}

subgraph clusterC {label = "C Shift c3 above b3";
    c0 -> c3;
}

A -> a0[lhead=clusterA];
B -> b0[lhead=clusterB];
C -> c0[lhead=clusterC];

a0 -> b0[constraint=false];
b3 -> c3[constraint=false];
a2 -> b2[constraint=false];
}

>Solution :

The minlen attribute (https://graphviz.org/docs/attrs/minlen/) applies to edges to lengthen them (i.e. to push them "out" by N ranks).
Then added invisible nodes and edges to increase cluster dimension.

digraph AlignWhenMissing {
rankdir=LR;
node [shape=box]

subgraph clusterA {label = "A Shift a4 along (no a3)";
    a0 -> a1;
    a1 -> a2;
    a2 -> a4 [minlen=2];
}

subgraph clusterB {label = "B Shift b2 above a2";
    b0 -> b2 [minlen=2]
    b2 -> b3;
    b4 [style=invis]
    b3 -> b4 [style=invis]
}

subgraph clusterC {label = "C Shift c3 above b3";
    c0 -> c3 [minlen=3];
    c4 [style=invis]
    c3 -> c4 [style=invis]
}

A -> a0[lhead=clusterA];
B -> b0[lhead=clusterB];
C -> c0[lhead=clusterC];

a0 -> b0[constraint=false];
b3 -> c3[constraint=false];
a2 -> b2[constraint=false];
}

Giving:
enter image description here

Leave a Reply