LaTeX Flow Chart Path Problem [duplicate]

This question already has an answer here:

I have a flow chart that has all of the nodes that I want, there is just one path that I can't get.

\begin{figure}[H]
\begin{center}

\tikzstyle{decision} = [diamond, draw, fill=blue!20,
text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20,
text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
minimum height=2em]

\begin{tikzpicture}[node distance = 3cm, auto]
% Place nodes
\node [block] (init) {Set Quotient to 0};
\node [block, below of=init] (identify) {Subtract Divisor from Dividend};
\node [block, below of=identify] (evaluate) {Add 1 to Quotient};
\node [decision, below of=evaluate] (decide) {is Result Register Greater than 0?};
\node [block, below of=decide, node distance=3cm] (stop) {Stop - Quotient is Correct};
% Draw edges
\path [line] (init) -- (identify);
\path [line] (identify) -- (evaluate);
\path [line] (evaluate) -- (decide);
\path [line] (decide) -- node {no}(stop);
\end{tikzpicture}

% use \figcap to build the caption. DO NOT use the default \caption command
\figcap{Control scheme for Repeated Subtraction Division} % put the caption of your figure here
\end{center}
\end{figure}

I would like to add a path that loops from the last block (stop) to the block (identify). Whenever I try to do this I get a path that does not go around the blocks, but rather through them.

Any ideas?

marked as duplicate by Qrrbrbirlbel, Guido, Andrew Swann, jub0bs, Claudio FiandrinoOct 22 '13 at 6:32

You can use relative coordinates (++(2cm,0)) then vertical-horizontal paths (|-) :

\path[line] (stop) -- ++(2cm,0) |- (identify);

The completed code using \tikzset instead of \tikzstyle (cf. Should \tikzset or \tikzstyle be used to define TikZ styles?)

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric,arrows}
\tikzset{%
decision/.style={
diamond, draw, fill=blue!20, text width=4.5em, text badly centered,
node distance=3cm, inner sep=0pt,
},
block/.style={
rectangle, draw, fill=blue!20, text width=5em, text centered,
rounded corners, minimum height=4em,
},
line/.style={
draw, -latex',
},
}
\begin{document}
\begin{tikzpicture}[node distance = 3cm, auto]
% Place nodes
\node [block] (init) {Set Quotient to 0};
\node [block, below of=init] (identify) {Subtract Divisor from Dividend};
\node [block, below of=identify] (evaluate) {Add 1 to Quotient};
\node [decision, below of=evaluate] (decide) {is Result Register Greater than 0?};
\node [block, below of=decide, node distance=3cm] (stop) {Stop - Quotient is Correct};
% Draw edges
\path [line] (init) -- (identify);
\path [line] (identify) -- (evaluate);
\path [line] (evaluate) -- (decide);
\path [line] (decide) -- node {no}(stop);
% Loop
\path[line] (stop) -- ++(-2cm,0) |- (identify);
\end{tikzpicture}
\end{document} May I suggest a second alternative via matrix notes from TikZ. In this way the vertical distance is set by the rowsep or (colsep for 2D orientations) without using node distance commands and the use below= of ... is minimal as well. (The same idea applies to 2D orientations, especially for flow chart diagram, IHMO) Code

\documentclass[tikz,border=1cm]{standalone}
\usetikzlibrary{matrix, shapes, arrows, positioning}
\begin{document}
\begin{figure}
\begin{center}
\tikzstyle{decision} = [diamond, draw, fill=blue!20,
text width=4.5em, text badly centered, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20,
text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse, fill=red!20, minimum height=2em]

\begin{tikzpicture}[auto]
% Place nodes with matrix nodes
\matrix[matrix of nodes, column sep=1cm, row sep=1cm]{%
\node [block] (init) {Set Quotient to 0};\\
\node [block] (identify) {Subtract Divisor from Dividend};\\
\node [block] (evaluate) {Add 1 to Quotient};\\
\node [decision] (decide) {is Result Register Greater than 0?};\\
\node [block] (stop) {Stop - Quotient is Correct};\\};
% Draw edges
\path [line] (init) -- (identify);
\path [line] (identify) -- (evaluate);
\path [line] (evaluate) -- (decide);
\path [line] (decide) -- node[right]{No} (stop);
\path [line] (stop) -- ++(2,0) |- (identify);
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}