12

我有以下代码,它会产生下图。如您所见,边缘和边缘标签周围有点拥挤,尤其是“^a”周围。创造更多空间的最佳方法是什么,以便人们可以清楚地看到哪个标签属于哪个边缘?

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>> ];
    }
}

在此处输入图像描述

4

3 回答 3

13

Graphviz中没有属性可以调整边缘标签周围的边距/填充。您可能最接近您需要的效果是使用\n在标签上方/下方引入空白行以强制空间。

显然,这不会自动扩展到任何东西。

或者,您可以尝试使用该ranksep属性来强制增加一些空间。

于 2013-09-23T12:38:40.737 回答
9

如果xlabel不能解决它,那么将标签包装在表格中有时可能是一种解决方法。例如:

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

要在一侧添加比另一侧更多的空间,您可以添加一个空单元格。然后代码很快变得(更多)不可读,但您可以使用简单的 sed 脚本来预处理您的点文件。

于 2015-12-01T20:18:21.643 回答
4

我知道这是一个老问题,但如果这是您正在寻找的,下面的这种方法也可能会有所帮助。见下图。我在您的代码中添加了以下内容:

  • minlen=2(扩大节点之间的间隙)

  • tailport=n/s(将箭头尾部的位置更改为北/南)

  • headport=n/s(将头部的位置更改为向北或向南的箭头)


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>> ];
    }
}

图片

于 2020-04-07T20:11:43.390 回答