TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to build a flowchart using the tikz environment but I'm having some trouble connecting the "No" line from decision to int (and from update to int). How can i draw a line avoiding overlapping?

% Define block styles
\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 = 4cm, auto]
    % Place nodes
    \node [block] (init) {Generazione scariche ($2^H$)};

    \node [block, left of=init] (W_legali) {$\mu_W$ \break $\rho_b^{-1}=\frac{P}{n_b+1}$};
    \node [block, right of=init] (W_nlegali) {$\mu_W$ \break $\rho_b^{-1}=\frac{P}{n_b}$};

     \node [block, below of=W_legali] (fo_legale) {$min$ $f.o_{W \ge W_L}$};
     \node [block, below of=W_nlegali] (fo_nlegale) {$min$ $f.o_{W < W_L}$};

    \node [decision, below of=init, node distance=6cm] (decide) {$min$ $f.o_{W \ge W_L}$ < $min$ $f.o_{W < W_L}$};
    \node [block, right of=fo_nlegale, node distance=3cm] (update) {Aggiorno $n_b$};

    % Draw edges
    \path [line] (init) -- node {$W_i \ge W_L$}(W_legali);
    \path [line] (init) -- node {$W_i < W_L$}(W_nlegali);
    \path [line] (W_legali) -- (fo_legale);
    \path [line] (W_nlegali) -- (fo_nlegale);

    \path [line] (fo_legale) -- (decide);
    \path [line] (fo_nlegale) -- (decide);

    \path [line] (decide) -| node [near start] {si} (update);
    \path [line] (decide) |- node {no} (init);


I strive for something like this (forget about line thickness):

enter image description here

share|improve this question
Please see Should \tikzset or \tikzstyle be used to define TikZ styles? and Difference between right of= and right=of in PGF/TikZ Furthermore, you’re minimal working example (MWE) misses the arrows and the shapes.geometric library. – Qrrbrbirlbel Sep 29 '13 at 10:04
up vote 5 down vote accepted

You need to do split your path up in a few sub-paths:

\path [line] (decide) -| node [near start] {no} ([xshift=-1cm] W_legali.west)
                      |- ([yshift=+1cm, xshift=-.2cm] init.north) coordinate (aux)
                      -- ([xshift=-.2cm] init.north);
\path [line] (update) |- ([xshift=.4cm] aux) -- ([xshift=.2cm] init.north);


  node distance = 2cm,
  decision/.style={diamond, draw, fill=blue!20, 
    text width=4.5em, align=center, node distance=3cm, inner sep=0pt},
  block/.style={rectangle, draw, fill=blue!20, 
    text width=5em, align=center, rounded corners, minimum height=4em},
  line/.style={draw, -latex'},
  cloud/.style={draw, ellipse,fill=red!20, node distance=3cm,
    minimum height=2em},
%  on grid
  % Place nodes
  \node [block] (init) {Generazio-ne scariche ($2^H$)};

  \node [block, left=of init]   (W_legali) {$\mu_W$ \\ $\rho_b^{-1}=\frac{P}{n_b+1}$};
  \node [block, right=of init] (W_nlegali) {$\mu_W$ \\ $\rho_b^{-1}=\frac{P}{n_b}$};

  \node [block, below=of W_legali]  (fo_legale)  {$\min$ $f.o_{W \ge W_L}$};
  \node [block, below=of W_nlegali] (fo_nlegale) {$\min$ $f.o_{W < W_L}$};

  \node [decision, below=3cm of init]   (decide)
                             {$\min$ $f.o_{W \ge W_L}$ \\${}< \min$ $ f.o_{W < W_L}$};
  \node [block,    right=of fo_nlegale] (update) {Aggiorno $n_b$};

  % Draw edges
  \path [line] (init) -- node[swap] {$W_i \ge W_L$} (W_legali);
  \path [line] (init) -- node       {$W_i < W_L$}   (W_nlegali);

  \path [line] (W_legali)   -- (fo_legale);
  \path [line] (W_nlegali)  -- (fo_nlegale);
  \path [line] (fo_legale)  -- (decide);
  \path [line] (fo_nlegale) -- (decide);

  \path [line] (decide) -| node [near start] {si} (update);
  \path [line] (decide) -| node [near start] {no} ([xshift=-1cm] W_legali.west)
                        |- ([yshift=+1cm, xshift=-.2cm] init.north) coordinate (aux)
                        -- ([xshift=-.2cm] init.north);
  \path [line] (update) |- ([xshift=.4cm] aux) -- ([xshift=.2cm] init.north);


enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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