我正在使用 Graphviz 绘制一些图表。我在节点上使用标签,我可以输入 "\n"
来强制它将标签分成两行。有没有某种方法可以让 Graphviz (或我正在使用的 dot
)自动看到它应该分割一些节点标签,并让它本身自动做出最佳选择?
I'm using Graphviz to draw some graphs. I'm using labels on nodes and I can put in "\n"
to force it to split the label across 2 lines. Is there some way to get Graphviz (or dot
which I'm using) to automatically see that it should split some nodes labels, and for it itself to make the best choice automagically?
发布评论
评论(4)
是的,类似 HTML 的标签 (
<...>
) 支持标记,您可以使用它来换行。例如,
当在 LaTeX 中嵌入 Graphviz 时,这些也可以工作,而
\n
则不行。Yes, HTML-like labels (
<...>
) supporttag, using which you can break the lines. E.g.
These also work when embedding Graphviz in LaTeX, where
\n
would not.我也搜索过这个,但我认为在当前版本中不可能。当前的“解决方案”是编写代码,根据节点之间的最小距离(
nodesep
属性,如果我没有记错的话),每隔几个字符自动添加“\n”。I've also searched for this, but I don't think it's possible in the current version. The current "solution" is to write code that automatically adds the "\n" every few characters, based on the minimum distance between nodes (
nodesep
attribute, if I'm not mistaken).有人编写了一个 Perl 脚本来实现这一目标。我在他的博客中找到了它: 用点 (graphviz) 进行文本换行。
:
将此程序保存为 setdotlabelwidth,然后只需将输出通过管道传输到 GraphViz 中。例如,如果要将宽度设置为 35 个字符,则命令为:
之前:
One person wrote a Perl script to achieve this. I found it in his blog: Text wrapping with dot (graphviz).
Perl script:
Save this program as setdotlabelwidth, then simply pipe the output into GraphViz. If for example you want to set the width to 35 characters, then the command is:
Before:
After:
(不确定我们应该如何处理重复的问题?)
dot2tex (latex + graphviz) 处理文本换行,
以及解决 graphviz 排版限制的其他解决方法。
您可以在这个重复问题中找到一个简短的示例,
具有规定的固定线宽。
(Not sure how we're supposed to deal with duplicate questions?)
dot2tex (latex + graphviz) handles text wrapping,
along with other workarounds to the typesetting limitations of graphviz.
You'll find a short example at this duplicate question,
with prescribed fixed line width.