语境:我想连接由库定位的 TikZ 图中节点部分。不幸的是,当我附加, , ... 后缀graphdrawing
时,它找不到节点。.first
.second
问题:
- 这个例子有什么问题吗?
- 有没有简单的方法可以解决这个限制?
最小工作示例失败graphdrawing
:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{graphdrawing,graphs,shapes}
\usegdlibrary{layered}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\begin{document}
\begin{tikzpicture}[layered layout]
\node
[rectangle split, rectangle split parts=4, text ragged]
(NodeA)
{
Node A
\nodepart{two}
Part two
\nodepart{three}
Part three
\nodepart{four}
Part four
};
\node
[rectangle split, rectangle split parts=3, text ragged]
(NodeB)
{
Node B
\nodepart{two}
Part two
\nodepart{three}
Part three
};
\draw (NodeA.two) edge[->] (NodeB.three);
\end{tikzpicture}
\end{document}
最小工作示例,不含graphdrawing
:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{graphs,shapes}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\begin{document}
\begin{tikzpicture}
\node
[rectangle split, rectangle split parts=4, text ragged]
(NodeA)
{
Node A
\nodepart{two}
Part two
\nodepart{three}
Part three
\nodepart{four}
Part four
};
\node
[rectangle split, rectangle split parts=3, text ragged]
(NodeB)
{
Node B
\nodepart{two}
Part two
\nodepart{three}
Part three
};
\draw (NodeA.two) edge[->] (NodeB.three);
\end{tikzpicture}
\end{document}
答案1
我不认为将多部分节点与图形绘制结合使用是一种恰当的搭配。特别是,很难看出自动放置算法在这种情况下如何正常工作。
例如,通过你的例子,我得到以下结果
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{graphdrawing,graphs,shapes.multipart}
\usegdlibrary{layered}
\begin{document}
\begin{tikzpicture}
\graph [layered layout]
{
nodeA [as={Node A \nodepart{two} Part two \nodepart{three} Part three \nodepart{four} Part four}, rectangle split, rectangle split parts=4, text ragged]
,
nodeB [as={Node B \nodepart{two} Part two \nodepart{three} Part three}, rectangle split, rectangle split parts=3, text ragged],
};
\draw (nodeA.two) edge[->] (nodeB.three);
\end{tikzpicture}
\end{document}
毫无疑问,这可以得到改进,但我想知道多部分节点究竟要做什么工作,如果需要自动布局,坚持使用具有更简单内部结构的节点是否更好。(或者至少不依赖锚点来明确地连接它们。)
产生这些疑虑的原因是,完成绘图的唯一方法是在命令范围之外进行\graph
,这意味着算法无法考虑所需的边缘。
然而,我对图形绘制库几乎一无所知,所以也许这是可能的。
\begin{rant}
The Tikz manual documents the use of nodes here very poorly, in my opinion.
Crucial information for actual use (e.g. how to include more than a single
letter in a node) is either mentioned but not given ("you can do this, but
we're not going to tell you how!") or provided only implicitly ("we won't
bother to explain 'as' but if you trawl through all the examples, maybe
you'll realise that it can be used to assign content which differs from
the node name").
TikZ is great and the documentation is mostly overwhelming but good.
However, the coverage of the graph drawing stuff seems more concerned to
show off technical wizardry than to tell the reader anything useful.
It wants to *impress* you.
Whether the reader can do anything useful with its wizardry is beside
the point.
\end{rant}