![Tikz - 带有矩阵和链的框图](https://linux22.com/image/438876/Tikz%20-%20%E5%B8%A6%E6%9C%89%E7%9F%A9%E9%98%B5%E5%92%8C%E9%93%BE%E7%9A%84%E6%A1%86%E5%9B%BE.png)
我正在尝试使用 tikz 绘制框图。为此,我想使用矩阵对齐节点,然后将节点与 tikzlibrary 连接起来chains
,如 pgfmanual 第 601 页(第 48 章)中所述。
但是,我想在某些块内放置自定义象形文字。一旦我这样做,我就无法将包含自定义象形文字的块链接在一起。
我从中得到了这个想法示例,我也无法编译。
考虑以下 MWE:
\usetikzlibrary{chains, scopes, matrix}
\begin{tikzpicture}
% I'd like to have a block with two circles within
\def\circles{
\node{};
\draw (-1mm,0) circle(2mm) (2mm,0) circle(2mm);
}
\matrix (m) [matrix of nodes,
nodes={draw,
minimum size=1cm,
align=center,
anchor=center},
column sep=1cm,
row sep=1cm,
]
{
A & B & C & \circles \\
};
{ [start chain, every on chain/.style={join=by ->}]
\chainin (m-1-1);
\chainin (m-1-2);
\chainin (m-1-3);
% \chainin (m-1-4); % once uncommented, it doesn't compile
};
\end{tikzpicture}
一旦我取消注释最后一条\chainin (m-1-4);
语句,我就会收到错误消息
[LaTeX] Line 87: Package pgf Error: No shape named `chain-1' is known.
[LaTeX] Line 87: See the pgf package documentation for explanation. ...
l.80 \chainin (m-1-4);
你知道如何在链接序列中将节点与这样的象形图连接起来吗?
答案1
如果您理解正确,那么您将遵循以下内容:
生成上述图像的 MWE 仅使用arrows.meta
、chains
和库。节点之间的箭头由库中定义的positioning
宏绘制。join
chains
\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{chains,
positioning}
\newcommand\dcircle{\tikz{\draw (-0.1,0) circle[radius=2mm] (0.1,0) circle[radius=2mm]}}
\begin{document}
\begin{tikzpicture}[
node distance = 1cm and 1cm,
start chain = going right,
N/.style = {draw, minimum size=1cm, semithick,
on chain, join=by ->}
]
\foreach \i [count=\x] in {A, B , C, \dcircle}
\node [N] {\i};
\end{tikzpicture}
\end{document}