![如何在 TikZ 中用矩形和箭头聚合各种节点?](https://linux22.com/image/278237/%E5%A6%82%E4%BD%95%E5%9C%A8%20TikZ%20%E4%B8%AD%E7%94%A8%E7%9F%A9%E5%BD%A2%E5%92%8C%E7%AE%AD%E5%A4%B4%E8%81%9A%E5%90%88%E5%90%84%E7%A7%8D%E8%8A%82%E7%82%B9%EF%BC%9F.png)
答案1
使编码复杂化以使其更容易理解。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{
block/.style = {draw,rectangle,minimum size=1cm,rounded corners = 1ex,thick}}
\begin{document}
\begin{tikzpicture}
%% first column
\node [block,draw=blue] (1a) {};
\node [block,draw=blue,below = 1cm of 1a] (1b) {};
\node [block,draw=blue,below = 1cm of 1b] (1c) {};
%% second column
\node [block,draw=green!70!blue,below right = 0cm and 2cm of 1a] (2a) {};
\node [block,draw=green!70!blue,below = 1cm of 2a] (2b) {};
%% paths
\draw[thick,magenta] (1a.-20) -| ([xshift=-1cm]2a.west)coordinate (a);
\draw[thick,magenta] (a) |- (1b.20);
\draw[thick,blue!60!green,-latex] (a) |- (2a.west);
\draw[thick,magenta] (1b.-20) -| ([xshift=-1cm]2b.west)coordinate (b);
\draw[thick,magenta] (b) |- (1c.20);
\draw[thick,blue!60!green,-latex] (b) |- (2b.west);
\end{tikzpicture}
\end{document}
答案2
通过 TiKZ 的矩阵节点进行另一种选择
代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,scopes}
\begin{document}
\tikzset{%
line/.style={draw, thick},
point/.style={coordinate},
boxes/.style={draw, rectangle,
thick,minimum height=2cm, rounded corners,
minimum width=1cm, text=black, thick,
text width=25mm, align=center}
}
\begin{tikzpicture}[scale=1]
% Place nodes
\matrix[column sep=1cm, row sep=0.5cm]{
\node [boxes,blue] (1a){}; & & \\
& \node[point](d){} &\node[boxes,green] (3a){}; \\
\node [boxes,blue] (1b){}; & & \\
& \node[point](e){}; &\node[boxes,green] (3b){}; \\
\node [boxes,blue] (1c){}; & & \\
};
% Draw edges
\path [line,magenta] ([shift={(0cm,-0.3cm)}]1a.east) -| (d) |- ([shift={(0cm,0.3cm)}]1b.east) ;
\path [line, -latex',blue!60!green] (d.east) -- (3a.west);
\path[line,magenta] ([shift={(0cm,-0.3cm)}]1b.east) -| (e) |- ([shift={(0cm,0.3cm)}]1c.east);
\path [line, -latex',blue!60!green] (e.east) -- (3b.west);
\end{tikzpicture}
\end{document}