在节点之间画箭头

在节点之间画箭头

我有 4 个节点,我需要画一个从一个节点到另一个节点转 2 次的箭头。

像这样。

\documentclass[tikz,border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\begin{document}
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{tikzpicture}[node distance=2cm]


\node (pro1) [process] {Process 1};
\node (dec1) [decision, below of=pro1, yshift=-0.5cm] {Decision 1};
\node (pro2b) [process, right of=dec1, xshift=2cm] {Process 2b};
\node (pro3b) [process, above of=pro2b] {Process 2a};


\draw [arrow] (pro1) -- (dec1);
\draw [arrow] (dec1) -| (pro3b) ;

\end{tikzpicture}
\end{document}

答案1

类似的问题经常出现在 TeX.SE 上...我在第二条评论中提供了一个链接。对于您的特定问题,最简单的解决方案似乎是在“决策”形状的右侧直接定义一个坐标:

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows, positioning, shapes.geometric}

    \begin{document}
\begin{tikzpicture}[
  node distance = 1cm and 2cm,
 process/.style = {rectangle, draw, fill=orange!30,
                   minimum width=3cm, minimum height=1cm, align=center},
decision/.style = {diamond, draw, fill=green!30,
                   minimum width=3cm, minimum height=1cm, align=center, draw=black},
   arrow/.style = {thick,-stealth}
                    ]
% nodes
\node (pro1)  [process] {Process 1};
\node (dec1)  [decision,below=of pro1]   {Decision 1};
\node (pro2b) [process, right=of dec1]   {Process 2b};
\node (pro3b) [process, above=of pro2b]  {Process 2a};
% connections
\draw [arrow] (pro1) -- (dec1);
\draw [arrow] (dec1.east) -- + (1,0) |- (pro3b);% <-- this solve your problem
\draw [arrow] (pro3b) -- (pro2b);
\end{tikzpicture}
    \end{document}

在上面的 MWE 中,您可以观察到,我改变了定义样式的方式(最新版本的 TikZ\tikzstyle{ ..} = [...]被替换为tikzset,或者像上面的 MWE 中所做的那样定义样式),其中我考虑了库positioning。这导致代码稍微更简洁。

得到的结果是:

在此处输入图片描述

相关内容