user1948258
user1948258

Reputation: 351

How can I get the boxes in the same line?

I have read this link --> Forcing "main line" nodes into a straight line in Graphviz (or alternatives)

Despite using this - I can not get this right. What do I do wrong?

Thanks!

F

<graphviz>

digraph MMM8
{
rankdir=LR

node [shape=box,  width="0.8", height="0.5", fontsize="10"];
edge [weight=2]
      1, 2, 3, 6, 7;
edge [weight=1]
      4, 5, Nod1,  8;

 node [shape = box];
        1 [label = "111111111111"];
        2 [label = "2"];
        3 [label = "3"];
        4 [label = "4"];
        5 [label = "5"];
        6 [label = "6"];
        7 [label = "7"];
        8 [label = "7"];
        9 [label = "9"];
Nod1 [label="N1", shape=diamond,style=filled,label="",height=.1,width=.1] ;
{
1-> 2[label="C1"]
2-> 3
3 -> Nod1 
4->Nod1
Nod1->5 
5->6 
6-> 7
5->8
8-> 9
9-> 7

 {
rank = same;
1, 4
}
{
rank = same;
6,8
}

}
</graphviz>

Upvotes: 2

Views: 1592

Answers (1)

Erik von Reis
Erik von Reis

Reputation: 11

You've got to create a subgroup with rank=same and include each node you want inline in the subgroup.

digraph MMM8
{
    rankdir=LR
    node [shape=box,  width="0.8", height="0.5", fontsize="10"];

    node [shape = box];
    {
        rank=same;
        1 [label = "111111111111"];
        2 [label = "2"];
        3 [label = "3"];
        6 [label = "6"];
        7 [label = "7"];
    }
    {
        rank=same;
        4 [label = "4"];
        5 [label = "5"];        
        8 [label = "8"];        
        Nod1 [label="N1", shape=diamond,style=filled,label="",height=.1,width=.1] ;
    }

    9 [label = "9"];

    1-> 2[label="C1"];
    2-> 3;
    3 -> Nod1; 
    4->Nod1;
    Nod1->5; 
    5->6 ;
    6-> 7;
    5->8;
    8-> 9;
    9-> 7;

}

If you want to get all those nodes in line, then you'll have to combine the two subgroups into one and move node 9 into it.

Upvotes: 1

Related Questions