graphviz中节点的垂直对齐

Vertical alignment of nodes in graphviz

我正在尝试制作 {C1;C2} 垂直对齐的图表。与 {A;B;C} 和 {E1;E2;E3} 相同

到目前为止,这是我的代码:

digraph G{
    rankdir="LR";
    S -> C1 [label="150"];
    S -> C2 [label="130"];
    C1 -> A [label="70"];
    C1 -> B [label="80"];
    C2 -> B [label="60"];
    C2 -> C [label="70"];
    C -> B [label="10"];
    A -> E1 [label="70"];
    B -> E1 [label="80"];
    B -> D [label="70"];
    C -> E3 [label="60"];
    D -> E1 [label="40"];
    D -> E2 [label="0"];
    D -> E3 [label="30"];
    E1 -> t [label="190"];
    E2 -> t [label="0"];
    E3 -> t [label="90"];
}

这是目前的结果:

{ rank = same; } 是你的朋友。我在 A、B 和 C 之间添加了不可见的边缘以使它们更紧密地结合在一起,并反转了其中一个连接以保持 A 高于 B 高于 C 等

digraph G
{
    rankdir="LR";
    { rank = same; C1 C2 }
    { rank = same; A -> B -> C[ style = invis ] }
    { rank = same; E1 E2 E3 }
    S -> C1 [label="150"];
    S -> C2 [label="130"];
    C1 -> A [label="70"];
    C1 -> B [label="80"];
    C2 -> B [label="60"];
    C2 -> C [label="70"];
    B -> C [dir = back, label="10"];   // to keep B above C
    A -> E1 [label="70"];
    B -> E1 [label="80"];
    B -> D [label="70"];
    C -> E3 [label="60"];
    D -> E1 [label="40"];
    D -> E2 [label="0"];
    D -> E3 [label="30"];
    E1 -> t [label="190"];
    E2 -> t [label="0"];
    E3 -> t [label="90"]; 
}

产量