如何在 TikZ 中用矩形和箭头聚合各种节点?

如何在 TikZ 中用矩形和箭头聚合各种节点?

我对 TikZ 还很陌生。我想加入一些节点,如附图所示

在此处输入图片描述

我从这个帖子中得到了一些想法树 矩形。但是,我无法用箭头正确实现这一点。如果您能分享您的意见/建议以实现这一点,我将不胜感激。

答案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}

相关内容