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 |
Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the
LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de.
En français: TeXnique.fr.
\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
A little improvement
i read it so it is intersting
Very helpful, thanks! It seems the code for formatting the yes/no nodes can also be styled:
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.
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.
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.
Section "16.6 Examples". Page 181 in the current CTAN version of the manual (PGF 2.0).
Found it, thanks!
Meanwhile this section has another number, so reference by name would be easier. ;-)
It's part III, chapter »Matrices and Alignment«, section »Examples«. 8-)
How do I do an other box around system, initialize model and expert? I need this for modified flow chart.
I want To learn how to make a flowchart easily!!
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];
@John Chain: Fixed.
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
@Jan: You can put nearly anything inside a node, including an eps or pdf:
Very helpful!
If the "update" block is removed ..how to connect the path between the decision block and the "identify" block
does anyone know if it possible to number the boxes in say the top right hand corner?
How can i make a flow a simple system with realimentation, that the line derive by another line and not by a box, for example? Thanks.
Thanks for this example!
One question for adapting it to my needs: How can I keep the edge from EVALUATE to INIT without having the node SYSTEM? I tried for example "|-|" but it won't work :(
good!!!
I have two questions: 1. How can I put a title of the flow chart, under the flow chart? 2. How can I put a block in the MIDDLE of two blocks, but below the both of blocks?
Thanks!
Zahid >
1) using \begin{figure} \caption{Figure} \end{figure}
2) using "right below" or "left below" ?
Thanks Tatill for your response, I now could put caption but couldn't use right below or left below commands.
Hi guys Im finding on my Miktex that the flow chart is not centred do you know how i can make it stay in the middle of my PDF like you have on yours?
Sorry I mean Texworks
24 @Allen Joseph.
To make it stay in center use something like this:
\documentclass{article} \usepackage[a4paper,margin=2.0cm]{geometry}
To make it a standalone picture (or pdf) with no borders (i.e. size automatically set to picture), use the standalone package instead:
\documentclass[tikz]{standalone}
Check page 7 from this manual for more: http://ctan.mirror.rafal.ca/macros/latex/contrib/standalone/standalone.pdf
I have to draw a stencil with two parallel lines and one perpendicular line cutting them in the middle and I also want to name their nodes. but I am not able to do this so please help me.
How can I move the "no" vertically?
I tried the example above with MIKTEX on Win7, and it compiled for a while, but them stopped with:
ABD: EveryShipout initializing macros) *
It seemed to be waiting for input from me at that point. Any suggestions?
Thanks Neal
How can you bend the arrows so that it doesn't go directly from one node to the other?
I would like to allow other users to drop lines of text into the blocks of a pre-constructed flowchart like this. I know the "box and arrow" skeleton of the flowchart, so to speak, but not the number of text lines in any particular block. (Every block will have at least one text line.) In the code given here, if I put too many text lines in block "A", that block will expand so as to clobber blocks below it. Is there a way to modify this script such that blocks and arrows below "A" will automatically "move down" to accomodate many lines of text in "A"?
Please ignore my previous two questions. BTW, I would have found a simple example of a flowchart that uses the \matrix command to be very useful. Most currently-available examples are pretty complex, at least for me.
Adding comments is currently not enabled.