oskarkv
oskarkv

Reputation: 2369

Graphviz --- edge label too close to another edge

I have the following code, and it results in the image below. As you can see, it's a little crowded around the edges and edge labels, especially around the "^a". What is the best way to create just a tad more space, so that one can clearly see which label belongs to which edge?

digraph finite_state_machine {                                                                                                                                                                                  
    pad=0.2;
    {
        rank=same;
        node [shape = point, style = invis]; q_0;
        node [shape = doublecircle, style = solid]; q_5;
        node [shape = circle];
        q_1 [ label = <<i>q<sub>1</sub></i>> ];
        q_2 [ label = <<i>q<sub>2</sub></i>> ];
        q_3 [ label = <<i>q<sub>3</sub></i>> ];
        q_4 [ label = <<i>q<sub>4</sub></i>> ];
        q_5 [ label = <<i>q<sub>5</sub></i>> ];
        q_0 -> q_1;
        q_1 -> q_2 [ label = "." ];
        q_1 -> q_2 [ label = <&epsilon;>, constraint=false ];
        q_2 -> q_1 [ label = <&epsilon;>, constraint=false ];
        q_2 -> q_3 [ label = <<i>a</i>> ];
        q_3 -> q_4 [ label = <<i>^a</i>> ];
        q_3 -> q_4 [ label = <&epsilon;>, constraint=false ];
        q_4 -> q_3 [ label = <&epsilon;>, constraint=false ];
        q_4 -> q_5 [ label = <<i>b</i>> ];
    }
}

enter image description here

Upvotes: 15

Views: 13344

Answers (3)

GSA
GSA

Reputation: 793

I know this is an old question, but this approach below might also be helpful, if this is what you are looking for. see the image below. i added the following to your code:

  • minlen=2 (to extend gaps between nodes)

  • tailport=n/s (to change location of the tail of the arrow to north/south)

  • headport=n/s (to change location of the head to the arrow to north or south)


digraph finite_state_machine {                                                                                                                                                                                  
    pad=0.2;
    {
        rank=same;
        node [shape = point, style = invis]; q_0;
        node [shape = doublecircle, style = solid]; q_5;
        node [shape = circle];
        q_1 [ label = <<i>q<sub>1</sub></i>> ];
        q_2 [ label = <<i>q<sub>2</sub></i>> ];
        q_3 [ label = <<i>q<sub>3</sub></i>> ];
        q_4 [ label = <<i>q<sub>4</sub></i>> ];
        q_5 [ label = <<i>q<sub>5</sub></i>> ];
        q_0 -> q_1;
        q_1 -> q_2 [ label = "." ];
        q_1 -> q_2 [ label = <&epsilon;>, constraint=false, minlen=2, tailport=n, headport=n];
        q_2 -> q_1 [ label = <&epsilon;>, constraint=false, minlen=2, tailport=s, headport=s];
        q_2 -> q_3 [ label = <<i>a</i>> ];
        q_3 -> q_4 [ label = <<i>^a</i>> ];
        q_3 -> q_4 [ label = <&epsilon;>, constraint=false, minlen=2, tailport=n, headport=n];
        q_4 -> q_3 [ label = <&epsilon;>, constraint=false, minlen=2, tailport=s, headport=s];
        q_4 -> q_5 [ label = <<i>b</i>> ];
    }
}

image

Upvotes: 6

Tilo
Tilo

Reputation: 3325

If xlabel doesn't solve it, then wrapping the label in a table can sometimes be a work-around. For example:

q_1 -> q_2 [ label = <<table cellpadding="10" border="0" cellborder="0">
                        <tr><td>&epsilon;</td></tr>
                      </table>>, 
             constraint = false ];

To add more space on one side than on another, you can add an empty cell. The code then quickly becomes (more) unreadable, but you could use a simple sed script to pre-process your dot file.

Upvotes: 9

Pekka
Pekka

Reputation: 3654

There is no attribute in Graphviz to adjust the margin/padding around edge labels. The closest you can probably get to the effect you require is to use \n to introduce blank lines above/below your label to force space.

Obviously, this will not scale to anything automatic.

Alternately, you could try to use the ranksep attribute to force in some additional space.

Upvotes: 14

Related Questions