0

This question already has an answer here:

Using just the {tikzpicture} environment I can place the flowchart right between two portions of text like this:

enter image description here

\documentclass{article}
\usepackage{float}                                      
\usepackage{caption}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes.geometric,positioning}

\begin{document}


\begin{tikzpicture}[
  node distance = 2cm,
  auto,
  decision/.style={diamond, draw, fill=blue!20, 
    text width=5.5em, align=center, node distance=3cm, inner sep=1pt},
  block/.style={rectangle, draw, fill=blue!20, 
    text width=7em, 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) {Generating combinations ($2^H$)};

  \node [block, left=of init, xshift=1.5cm ,yshift=-3cm]   (W_legali) {$E(W     \ge     W_L$) \\ $n_B = n_B + 1$};
  \node [block, right=of init, xshift=-1.5cm , yshift=-3cm] (W_nlegali) {$E(W   <       W_L$) \\ $n_B = n_B$};

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

  \node [decision, below=6cm of init, yshift=-1.5cm]   (decide)
                             {$z_{(W \ge W_L)}$ \\ $\ge$ \\ $z_{(W < W_L)}$};
  \node [block, right=of fo_nlegale, xshift=-2cm, yshift=6cm] (update) {Updating $n_B$};

  % Draw edges
  \path [line] (init) -- node[swap] {$W \ge W_L$} (W_legali);
  \path [line] (init) -- node       {$W < 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] {yes} (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);
\end{tikzpicture}
\end{document}

But, using the {figure} environment, to be able to add a caption, my flowchart moves to another page and it's not between of the text portions anymore.

enter image description here

\documentclass{article}
\usepackage{float}                                      
\usepackage{caption}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes.geometric,positioning}

\begin{document}

\begin{figure}[h]
\begin{tikzpicture}[
  node distance = 2cm,
  auto,
  decision/.style={diamond, draw, fill=blue!20, 
    text width=5.5em, align=center, node distance=3cm, inner sep=1pt},
  block/.style={rectangle, draw, fill=blue!20, 
    text width=7em, 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) {Generating combinations ($2^H$)};

  \node [block, left=of init, xshift=1.5cm ,yshift=-3cm]   (W_legali) {$E(W     \ge     W_L$) \\ $n_B = n_B + 1$};
  \node [block, right=of init, xshift=-1.5cm , yshift=-3cm] (W_nlegali) {$E(W   <       W_L$) \\ $n_B = n_B$};

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

  \node [decision, below=6cm of init, yshift=-1.5cm]   (decide)
                             {$z_{(W \ge W_L)}$ \\ $\ge$ \\ $z_{(W < W_L)}$};
  \node [block, right=of fo_nlegale, xshift=-2cm, yshift=6cm] (update) {Updating $n_B$};

  % Draw edges
  \path [line] (init) -- node[swap] {$W \ge W_L$} (W_legali);
  \path [line] (init) -- node       {$W < 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] {yes} (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);
\end{tikzpicture}
\caption{Iterative rules flow chart} \label{fig:flowchart}
\end{figure}
\end{document}

marked as duplicate by Ludovic C., henrique, jub0bs, Benedikt Bauer, Stefan Kottwitz Oct 28 '13 at 11:58

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.

Browse other questions tagged or ask your own question.