Example: Simple flow chart

Published 2006-11-20 | Author: Kjell Magne Fauske

With PGF/TikZ you can draw flow charts with relative ease. This flow chart from [1] outlines an algorithm for identifying the parameters of an autonomous underwater vehicle model.

Note that relative node placement has been used to avoid placing nodes explicitly. This feature was introduced in PGF/TikZ >= 1.09.

[1]Bossley, K.; Brown, M. & Harris, C. Neurofuzzy identification of an autonomous underwater vehicle International Journal of Systems Science, 1999, 30, 901-913

Download as: [PDF] [TEX]

Simple flow chart
\documentclass{article}

\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}


% 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 = 2cm, auto]
    % Place nodes
    \node [block] (init) {initialize model};
    \node [cloud, left of=init] (expert) {expert};
    \node [cloud, right of=init] (system) {system};
    \node [block, below of=init] (identify) {identify candidate models};
    \node [block, below of=identify] (evaluate) {evaluate candidate models};
    \node [block, left of=evaluate, node distance=3cm] (update) {update model};
    \node [decision, below of=evaluate] (decide) {is best candidate better?};
    \node [block, below of=decide, node distance=3cm] (stop) {stop};
    % Draw edges
    \path [line] (init) -- (identify);
    \path [line] (identify) -- (evaluate);
    \path [line] (evaluate) -- (decide);
    \path [line] (decide) -| node [near start] {yes} (update);
    \path [line] (update) |- (identify);
    \path [line] (decide) -- node {no}(stop);
    \path [line,dashed] (expert) -- (init);
    \path [line,dashed] (system) -- (init);
    \path [line,dashed] (system) |- (evaluate);
\end{tikzpicture}


\end{document}

Comments

  • #1 Blithe, January 12, 2009 at 11:17 p.m.

    A little improvement

    \tikzstyle{decision} = [diamond, draw, fill=blue!20,
        text width=4.5em, text badly centered, node distance=2.5cm, inner sep=0pt]
    \tikzstyle{block} = [rectangle, draw, fill=blue!20,
        text width=5em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{line} = [draw, very thick, color=black!50, -latex']
    \tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=2.5cm,
        minimum height=2em]
    
    \begin{tikzpicture}[scale=2, node distance = 2cm, auto]
        % Place nodes
        \node [block] (init) {initialize model};
        \node [cloud, left of=init] (expert) {expert};
        \node [cloud, right of=init] (system) {system};
        \node [block, below of=init] (identify) {identify candidate models};
        \node [block, below of=identify] (evaluate) {evaluate candidate models};
        \node [block, left of=evaluate, node distance=2.5cm] (update) {update model};
        \node [decision, below of=evaluate] (decide) {is best candidate better?};
        \node [block, below of=decide, node distance=2.5cm] (stop) {stop};
        % Draw edges
        \path [line] (init) -- (identify);
        \path [line] (identify) -- (evaluate);
        \path [line] (evaluate) -- (decide);
        \path [line] (decide) -| node [near start, color=black] {yes} (update);
        \path [line] (update) |- (identify);
        \path [line] (decide) -- node [, color=black] {no}(stop);
        \path [line,dashed] (expert) -- (init);
        \path [line,dashed] (system) -- (init);
        \path [line,dashed] (system) |- (evaluate);
    \end{tikzpicture}
    
  • #2 sintayhu, February 17, 2009 at 2:21 a.m.

    i read it so it is intersting

  • #3 Matthew Leingang, March 25, 2009 at 2:29 p.m.

    Very helpful, thanks! It seems the code for formatting the yes/no nodes can also be styled:

    \tikzstyle{decision answer}=[near start,color=black]
    ...
    \path[line] (decide) -| node[decision answer] {yes} (update);
    

    You can also use anchors like decide.east if you want to force the arrows to come out of the points of the decision rhombus. This isn't needed here but if you want a diagonal line coming out of the decision node it will by default come from the center and emerge from one of the sides.

  • #4 Kjell Magne Fauske, March 25, 2009 at 2:41 p.m.

    In the PGF >= 2.0 manual there is a version of this flow chart that uses a tikz matrix to place the blocks. Requires less typing than my version.

  • #5 Matthew Leingang, March 25, 2009 at 5:46 p.m.

    I have the 2.0 manual and I didn't catch it, which is why I turned to google and found this page. Guess I'll look harder.

  • #6 Kjell Magne Fauske, March 26, 2009 at 8:46 a.m.

    Section "16.6 Examples". Page 181 in the current CTAN version of the manual (PGF 2.0).

  • #7 Matthew Leingang, March 26, 2009 at 2:15 p.m.

    Found it, thanks!

  • #8 LeSpocky, May 24, 2009 at 6:53 p.m.

    Meanwhile this section has another number, so reference by name would be easier. ;-)

    It's part III, chapter »Matrices and Alignment«, section »Examples«. 8-)

  • #9 Matze, August 18, 2009 at 11:15 a.m.

    How do I do an other box around system, initialize model and expert? I need this for modified flow chart.

  • #10 marla, October 14, 2009 at 3 a.m.

    I want To learn how to make a flowchart easily!!

  • #11 John Chain, January 7, 2010 at 9:33 p.m.

    Drop the semicolon for avoiding the semicolon at the top of the picture.

    tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm, minimum height=2em];

  • #12 Kjell Magne Fauske, January 11, 2010 at 7:56 p.m.

    @John Chain: Fixed.

  • #13 Jan Verbesselt, June 8, 2010 at 2:26 p.m.

    Would it be possible to include a figure (e.g. eps from R software) within a block so that it can be included in the flow chart?

    Thanks, Jan

  • #14 Kjell Magne Fauske, June 9, 2010 at 7:48 a.m.

    @Jan: You can put nearly anything inside a node, including an eps or pdf:

    ...    
    \node [block] (init) {\includegraphics{figure}};
    ...
    
  • #15 Travis, July 24, 2010 at 3:42 p.m.

    Very helpful!

  • #16 emad, August 10, 2010 at 2:15 p.m.

    If the "update" block is removed ..how to connect the path between the decision block and the "identify" block

Post a comment

Markdown syntax enabled. No HTML allowed.