【问题标题】:How to left align multiple line text literal in TABLE label of graphviz dot node?如何在graphviz点节点的TABLE标签中左对齐多行文本文字?
【发布时间】:2020-10-27 16:54:29
【问题描述】:

我有这样一个graphviz dot 文件test.dot,包含一个带有TABLE 标签的节点:

digraph {
    node [shape=none, fontname="Courier New, Courier"]
    edge [fontname="Courier New, Courier"]
    graph [fontname="Courier New, Courier"]

    id2765 [label=<<TABLE CELLBORDER="1" CELLSPACING="0" BORDER="0">
        <TR><TD PORT="cell756">literal</TD><TD PORT="cell757" ALIGN="LEFT">"""--- multiple line string literal with unicode ---
here we begin with some comments \\u0020 \\U00000000 \\u1234 \\u20AC \\U00008000:
multiple string literal begins and ends with triple quotes \\"\\"\\",
then newline are enabled in it.
here we test back slask \\r\\n \\' \\" \\? \\a \\b \\f \\n \\r \\t \\v \\\\.
"""</TD></TR>
    </TABLE>>]
}

请注意我希望节点包含多行文本文字:

"""--- multiple line string literal with unicode ---
here we begin with some comments \\u0020 \\U00000000 \\u1234 \\u20AC \\U00008000:
multiple string literal begins and ends with triple quotes \\"\\"\\",
then newline are enabled in it.
here we test back slask \\r\\n \\' \\" \\? \\a \\b \\f \\n \\r \\t \\v \\\\.
"""

dot -Tpng test.dot -o test.dot.png编译,它的输出:

您可以看到文本文字中没有换行。所以我用ALIGN="LEFT"&lt;BR/&gt;更新了test.dot

digraph {
    node [shape=none, fontname="Courier New, Courier"]
    edge [fontname="Courier New, Courier"]
    graph [fontname="Courier New, Courier"]

    id2765 [label=<<TABLE CELLBORDER="1" CELLSPACING="0" BORDER="0">
        <TR><TD PORT="cell756">literal</TD><TD PORT="cell757" ALIGN="LEFT">"""--- multiple line string literal with unicode ---<BR/>here we begin with some comments \\u0020 \\U00000000 \\u1234 \\u20AC \\U00008000:<BR/>    multiple string literal begins and ends with triple quotes \\"\\"\\",<BR/>    then newline are enabled in it.<BR/>    here we test back slask \\r\\n \\' \\" \\? \\a \\b \\f \\n \\r \\t \\v \\\\.<BR/>    """</TD></TR>
    </TABLE>>]
}

再次编译,它的输出:

有新的换行符,但文本居中对齐,而我想左对齐。

如何在graphviz点节点的TABLE标签中左对齐多行文本文字?

【问题讨论】:

    标签: graph label graphviz


    【解决方案1】:

    ALIGN="LEFT" 添加到每个&lt;BR/&gt;BALIGN="LEFT"&lt;TD ...&gt;,如下所示:

    digraph {
        node [shape=none, fontname="Courier New, Courier"]
        edge [fontname="Courier New, Courier"]
        graph [fontname="Courier New, Courier"]
    
        id2765 [label=<<TABLE CELLBORDER="1" CELLSPACING="0" BORDER="0">
            <TR><TD PORT="cell756">literal</TD><TD PORT="cell757" ALIGN="LEFT" BALIGN="LEFT">"""--- multiple line string literal with unicode ---<BR ALIGN="LEFT"/>here we begin with some comments \\u0020 \\U00000000 \\u1234 \\u20AC \\U00008000:<BR ALIGN="LEFT"/>    multiple string literal begins and ends with triple quotes \\"\\"\\",<BR ALIGN="LEFT"/>    then newline are enabled in it.<BR ALIGN="LEFT"/>    here we test back slask \\r\\n \\' \\" \\? \\a \\b \\f \\n \\r \\t \\v \\\\.<BR ALIGN="LEFT"/>    """</TD></TR> 
        </TABLE>>]
    }
    

    给予:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-16
      • 2022-01-01
      • 2021-11-30
      • 1970-01-01
      • 2021-12-06
      • 2021-01-27
      相关资源
      最近更新 更多