使用 Tikz 在流程图中实现连续节点

使用 Tikz 在流程图中实现连续节点

如何使用 Tikz 连接节点而不使用任何块?例如,我试图连接返回到 do-loop 的箭头,此时决策框(命名为条件) 返回。但是,您可以在下面的 Latex 代码中看到两个箭头断开了!有什么帮助吗?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, shadows}

\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30, drop shadow]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, text width=3cm, 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]
\tikzstyle{line} = [draw, -latex']
\begin{document}

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

\node (start) [startstop] {Start};
\node (in1) [io, below of=start] {Input};
\node (pro1) [process, below of=in1] {Process 1};
\node (dec1) [decision, below of=pro1, yshift=-0.5cm] {Condn};
%\node (pro2b) [process, right of=dec1, xshift=2cm] {};
\node (pro2b) [arrow, right of=dec1, xshift=3cm] {};
\node (out1) [io, below of=dec1] {Output};
\node (stop) [startstop, below of=out1] {Stop};

\draw [arrow] (start) -- (in1);
\draw [arrow] (in1) -- (pro1);
\draw [arrow] (pro1) -- (dec1);
\draw [arrow] (dec1) -- node[anchor=west] {yes} (out1);
\draw [arrow] (dec1) -- node[anchor=south] {no} (pro2b);
\draw [arrow] (pro2b) |- (pro1);
      % \path[-,draw] (dec1) -| node{} (inv.north);
      % \path[line]{} (inv.north) |- node[above]{no} (pro1);
\draw [arrow] (dec1) -- (out1);
\draw [arrow] (out1) -- (stop);


\end{tikzpicture}

\end{document}

我也附上了我的输出(根据在线找到的示例代码进行了修改)。

enter image description here

答案1

这个问题有多种解决方案。你可以插入一个带有上述标签的空节点来完整绘制路径:

\draw [arrow] (dec1.east) -- ++(5em,0) node[above] {no}
                          -- ++(5em,0) |- (pro1.east);

这样整个图就画出来了:

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

\node (start) [startstop] {Start};
\node (in1) [io, below of=start] {Input};
\node (pro1) [process, below of=in1] {Process 1};
\node (dec1) [decision, below of=pro1, yshift=-0.5cm] {Condn};
\node (pro2b) [arrow, right of=dec1, xshift=3cm] {};
\node (out1) [io, below of=dec1] {Output};
\node (stop) [startstop, below of=out1] {Stop};

\draw [arrow] (start) -- (in1);
\draw [arrow] (in1) -- (pro1);
\draw [arrow] (pro1) -- (dec1);
\draw [arrow] (dec1) -- node[anchor=west] {yes} (out1);
\draw [arrow] (dec1.east) -- ++(5em,0) node[above] {no}
                          -- ++(5em,0) |- (pro1.east);
\draw [arrow] (dec1) -- (out1);
\draw [arrow] (out1) -- (stop);

\end{tikzpicture}

答案2

我添加了一个额外的指令框。但是,决策框下方的箭头太小,而且还重叠!有什么方法可以明显延长箭头吗?

代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, shadows}

\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30, drop shadow]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, text width=3cm, 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]
\tikzstyle{line} = [draw, -latex']
\begin{document}

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

\node (start) [startstop] {Start};
\node (in1) [io, below of=start] {Input};
\node (pro1) [process, below of=in1] {Process 1};
\node (pro2) [process, below of=pro1] {Process 2};
\node (dec1) [decision, below of=pro2, yshift=-0.5cm] {Is $X-Y=Z$ ?};
\node (out1) [io, below of=dec1] {Output};
\node (stop) [startstop, below of=out1] {Stop};

\draw [arrow] (start) -- (in1);
\draw [arrow] (in1) -- (pro1);
\draw [arrow] (pro1) -- (pro2);
\draw [arrow] (pro2) -- (dec1);
\draw [arrow] (dec1) -- node[anchor=west] {yes} (out1);
\draw [arrow] (dec1.east) -- ++(5em,0) node[above] {no}
                          -- ++(5em,0) |- (pro1.east);
\draw [arrow] (dec1) -- (out1);
\draw [arrow] (out1) -- (stop);


\end{tikzpicture}

\end{document}

输出:

enter image description here

相关内容