如何将节点与 TikZ 连接?

如何将节点与 TikZ 连接?

希望你能帮助我。我想像附图中那样连接这些节点。我尝试使用链,但无法成功。我想使用最佳方式连接节点。

\documentclass{article}
\title{New}
\usepackage{tikz}
\usetikzlibrary{chains}

\begin{document}
\begin{center}
\begin{tikzpicture}

 \draw (6,3) node (problema) [draw,rounded corners,align=left,text width=50mm]{\small{\center \textbf{TITLE}\\ Text text text text text text text text text text text text text text text text text text text}};

 \draw (0,0) node (causa1) [draw,rounded corners,align=left,text width=40mm]{\small{\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text}};
 \draw (6,0) node (causa2) [draw,rounded corners,align=left,text width=40mm]{\small{ \textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text}};
 \draw (12,0) node (causa3) [draw,rounded corners,align=left,text width=40mm]{\small{ \textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text}};

\draw (problema) -| (causa1);
\draw (problema) -- (causa2);
\draw (problema) -| (causa3);

 \draw (0,-2.2) node (indir1) [draw,rounded corners,align=left,text width=30mm]{\small{\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text}};
 \draw (0,-4.4) node (indir2) [draw,rounded corners,align=left,text width=30mm]{\small{\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text}};
 \draw (0,-6.6) node (indir3) [draw,rounded corners,align=left,text width=30mm]{\small{\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text}};
 \draw (0,-8.8) node (indir4) [draw,rounded corners,align=left,text width=30mm]{\small{\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text}};

 \draw (6,-2.2) node (indir5) [draw,rounded corners,align=left,text width=30mm]{\small{\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text}};
 \draw (6,-4.4) node (indir6) [draw,rounded corners,align=left,text width=30mm]{\small{\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text}};
 \draw (6,-6.6) node (indir7) [draw,rounded corners,align=left,text width=30mm]{\small{\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text}};
 \draw (6,-8.8) node (indir8) [draw,rounded corners,align=left,text width=30mm]{\small{\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text}};
 \draw (6,-11) node (indir9) [draw,rounded corners,align=left,text width=30mm]{\small{\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text}};

 \draw (12,-2.2) node (indir10) [draw,rounded corners,align=left,text width=30mm]{\small{\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text}};

\end{tikzpicture}
\end{center}

\end{document}

在此处输入图片描述

答案1

您可以为此使用相对坐标。顶部的示例可以是:

\draw (problema) -- ++(0, -10pt) -| (causa1);

其余部分类似。稍微移动线然后使用直角链接。

答案2

你可以使用链条来实现这一点!甚至更好的是,我们可以使用该选项自动绘制线条join

但首先要做的事情是:请使用样式。并且请使用positioning库(由库加载chains)来放置节点,而不是硬编码坐标。positioning库使放置节点更加直观,并确保节点不会重叠。

我使用了我的paths.ortho库及其路径运算符lrrl。该库本身来自我的答案如何绘制从节点 3 到节点 1 的返回箭头(但不要使用该答案中的代码)并在我的另一个答案

如果没有这个paths.ortho库,place nodes on chain and install special path样式的定义将是

place nodes on chain and install special path/.style n args={3}{
  every node/.append style={on chain=#1,join},
  every join/.append style={to path=(#1-begin.#3) #2 (\tikztotarget)}
}

然后可以用作

place nodes on chain and install special path={ch1}{-- ++(left:.5cm) |-}{west}
place nodes on chain and install special path={ch2}{-- ++(left:.5cm) |-}{west}

place nodes on chain and install special path={ch}{-- ++(right:.5cm) |-}{east}

同时具有相同的输出。

代码

\documentclass[tikz,convert]{standalone}
\usetikzlibrary{chains,paths.ortho}

\begin{document}
\begin{tikzpicture}[
  ultra thick,
  node distance=1cm and 2cm,
  every node/.append style={
    draw,
    rounded corners,
    align=left,
    font=\small
  },
  top node/.style={text width=+55mm},
  wide node/.style={text width=+40mm},
  thin node/.style={text width=+30mm},
  start chain/.list={ch1 going below, ch2 going below, ch3 going below}
]

\node[top node](problema) {\textbf{TITLE}\\ Text text text text text text text text text text text text text text text text text text text};

\begin{scope}[every node/.append style={wide node}]
  \node[below=of problema, on chain=ch2] (causa2) {\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text};
  \node[left=of causa2   , on chain=ch1] (causa1) {\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text};
  \node[right=of causa2  , on chain=ch3] (causa3) {\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text};
\end{scope}
\begin{scope}[
  every node/.append style={thin node},
  place nodes on chain and install special path/.style 2 args={
    every node/.append style={on chain=#1,join},every join/.append style={to path=(#1-begin) #2 (\tikztotarget)}
  }
]
  \begin{scope}[place nodes on chain and install special path={ch1}{lr}]
    \node {\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text};
    \node {\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text};
    \node {\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text};
    \node {\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text};
  \end{scope}
  \begin{scope}[place nodes on chain and install special path={ch2}{lr}]
    \node {\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text};
    \node {\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text};
    \node {\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text};
    \node {\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text};
    \node {\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text};
  \end{scope}
  \begin{scope}[place nodes on chain and install special path={ch3}{rl}]
    \node {\textbf{Title}\\ Text text text text text text text text text text text text text text text text text text text};
  \end{scope}
\end{scope}

\draw (problema) -| (causa1);
\draw (problema) -- (causa2);
\draw (problema) -| (causa3);
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

相关内容