Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

marked as duplicate by Qrrbrbirlbel, Guido, Andrew Swann, Jubobs, Claudio Fiandrino Oct 22 '13 at 6:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

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}

enter image description here

share|improve this answer

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)

enter image description here

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}
share|improve this answer
    
Note that it is better to exploit tikzset rather than tikzstyle; see: Should \tikzset or \tikzstyle be used to define TikZ styles?. –  Claudio Fiandrino Oct 22 '13 at 6:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.