Make graphviz nodes left align
Asked Answered
O

2

7

I want the nodes in the second column (C and E) to left align, rather than center.

digraph left {
    graph [rankdir="LR", splines=ortho];
    node [shape=record];

    l1 [label="A\l|B\l"];
    l2 [label="C\l|short\l"];
    l3 [label="E\l|long long text\l"];

    l1 -> l2;
    l1 -> l3;
}

enter image description here

I have seen this question.

But the suggested method of using constant width for nodes is not suitable for me. I want to have them different widths depending on corresponding label widths.

Ordinand answered 24/10, 2014 at 4:39 Comment(0)
M
2

It seems that the node position in a graph is in all situations calculated from it's center. Until there is no other implementation, the only way to achieve an "aligned" look-a-like is to use a fitting width.

digraph left {
    graph [rankdir=LR splines=ortho]
    node [shape=record]

    l1 [label="A\l|B\l"]
    l2 [label="C\l|short\l" width=1.3]
    l3 [label="E\l|long long text\l"]

    l1 -> l2
    l1 -> l3
}

results in this: enter image description here

Mixup answered 12/3, 2018 at 0:18 Comment(0)
D
0

Answered here: Top-align nodes

Adding node[rankjustify=min] before "l1" and following the instructions pointed to above will give:
enter image description here

Digitoxin answered 14/3, 2023 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.