TikZ-PGF – How to Draw a Flow Chart in TikZ

tikz-pgf

I have some old drawings prepared in Word which I would like to translate into TikZ. Being a complete novice and having never worked with TikZ before, I am really struggling with getting started.

Here is the first flow chart that I want to convert:

Flow chart to be converted from LaTeX to TikZ

One solution that appealed to me due to its simplicity was using a matrix and chains as explained in a tutorial in the manual. But then I already run into trouble with the two arrows that have to point to boxes 1, 2, and 3.

So my question boils down to: What is the easiest way to convert this chart into TikZ?
Don't worry I'm not asking for code. I just want to know how to start, because finding your way in something as complex as TikZ, with an 800 page manual!, can be very frustrating for a beginner.


Update Oct 17, 2011

Getting the hang of it! Here is the output I can currently produce. Last question:
Any ideas how to align the arrows by their tips?

\documentclass[ngerman]{scrartcl}

\usepackage{ucs}
\usepackage[utf8x]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,calc}

\begin{document}

\tikzstyle{block} = [rectangle, fill=blue!20, minimum height=3em, minimum width=6em] \tikzstyle{arrow} = [single arrow, draw]

\begin{tikzpicture}[auto, node distance=0.5cm and 0.5cm, arr/.style={->,thick}, line/.style={thick}, font=\footnotesize]

\node (stoffVor) [block] {Box 1 text};
\node (haupt) [block, right=of stoffVor, align=center] {Box 2 text};
\node (stoffNach) [block, right=of haupt] {Box 3 text};
\node (pfeil1) [arrow, below left=of stoffVor] {Arrow 1};
\node (pfeil2) [arrow, below=of pfeil1] {Arrow 2 text};
\node (pfeil0) [arrow, left=of stoffVor] {Arrow 3 longer text};
\node (neben) [arrow, below right=of stoffNach, label=below:, yshift=0.5cm, xshift=1cm] {Text};
\node (hauptP) [arrow, above right=of stoffNach, label=above:,yshift=-0.5cm,xshift=1cm] {Text};
\node (pfeil3) [arrow, above=of hauptP] {Text};
\node (pfeil4) [arrow, above=of pfeil3] {Lorem, Ipsum, Dolor, Sit};

\draw[arr] (pfeil0.east) -- (stoffVor.west);
\draw[arr] (stoffVor.east) -- (haupt.west);
\draw[arr] (haupt.east) -- (stoffNach.west);
\draw[arr] (stoffNach.north) --  ++(0,0.5) node [auto, swap, yshift=6] {Text} -| ($ (stoffVor.east) + (0.25,0) $);
\draw[arr] (pfeil1.east) -| (stoffVor.240);
\draw[arr] (pfeil1.east) -| (haupt.240);
\draw[arr] (pfeil1.east) -| (stoffNach.240);
\draw[arr] (pfeil2.east) -| (stoffVor.300);
\draw[arr] (pfeil2.east) -| (haupt.300);
\draw[arr] (pfeil2.east) -| (stoffNach.300);
\draw[line] (haupt.150) |-  (pfeil4.west);
\draw[line] (haupt.30) |-  (pfeil3.west);
\draw[line] (stoffNach.350) -- ++ (0.25,0) -- ++ (0,-0.1) |- (neben.west);
\draw[line] (stoffNach.10) -- ++ (0.25,0) -- ++ (0, +0.1) |- (hauptP.west);

\end{tikzpicture}

\end{document}

enter image description here

Best Answer

The boxes could be nodes, something like

\node (box1) at (0,2) [rectangle,draw=black,fill=blue!20!white] {Box 1};

Notice the (box1), thats the name of that node, you can use it for easily drawing arrows:

\draw[->] (box1.east) -- (box2.west);

For the arrows with kinks, you can use the ++(x,y) coordinate notation, which means 'from the last position, go x right and y up, then make this the new position':

\draw[->] (box1.north) -- ++(0,1) -- ++(4,0) -- (box2.north);

Hope this helps getting started :)


Edit 1: You really learn TikZ by doing. I was wondering how to draw the double arrows entering the boxes on the south side. You could use the fact that you can specify any angle at which the arrows leave/enter:

\draw[->] (box1.300) -- ++(0,-0.5) -- ++(4,0) -- (box2.240);
\draw[->] (box1.240) -- ++(0,-1.0) -- ++(4,0) -- (box2.300);

However, the distance between entry and exit point is no longer 4. So it would be nice to specify 1cm below box2.240 which you can do with the calc library:

\coordinate (A) at ($ (box2.240) + (0,-0.5) $);
\coordinate (B) at ($ (box2.300) + (0,-1.0) $);
\draw[->] (box1.300) -- ++(0,-0.5) -- (A) -- (box2.240);
\draw[->] (box1.240) -- ++(0,-1.0) -- (B) -- (box2.300);

This should cover most things needed for your chart. Here a little example and a picture:

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
\node (box1) at (0,0) [rectangle,draw=black,fill=blue!20!white] {Box 1};
\node (box2) at  (4,0) [rectangle,draw=black,fill=blue!20!white] {Box 2};
\draw[->] (box1.east) -- (box2.west);
\draw[->] (box1.north) -- ++(0,1) -- ++(4,0) -- (box2.north);
\coordinate (A) at ($ (box2.240) + (0,-0.5) $);
\coordinate (B) at ($ (box2.300) + (0,-1.0) $);
\draw[->] (box1.300) -- ++(0,-0.5) -- (A) -- (box2.240);
\draw[->] (box1.240) -- ++(0,-1.0) -- (B) -- (box2.300);
\end{tikzpicture}

\end{document}

enter image description here


Edit 2: A nice, calc free version by percusse:

\begin{tikzpicture}
 \node (box1) at (0,0) [draw,fill=blue!20!white] {Box 1};
 \node (box2) at (4,0) [draw,fill=blue!20!white] {Box 2};
 \draw[->] (box1) -- (box2);
 \draw[->] (box1.north) -- ++(0,1) -| (box2.north);
 \draw[->] (box1.300) -- ++(0,-0.5) -| (box2.240);
 \draw[->] (box1.240) -- ++(0,-1.0) -| (box2.300);
\end{tikzpicture}

Edit 3: Regarding the request for tip aligned arrows: I could not (right now) think of anything elegent, so I used absolute coordinates and the left option, e.g. draw the node left of the coordinates, e.g. ending at the specified coordinates:

\documentclass[ngerman]{scrartcl}

\usepackage{ucs}
\usepackage[utf8x]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,calc}

\begin{document}

\tikzstyle{block} = [rectangle, fill=blue!20, minimum height=3em, minimum width=6em] \tikzstyle{arrow} = [single arrow, draw]

\begin{tikzpicture}[auto, node distance=0.5cm and 0.5cm, arr/.style={->,thick}, line/.style={thick}, font=\footnotesize]

\node (stoffVor) [block] {Box 1 text};
\node (haupt) [block, right=of stoffVor, align=center] {Box 2 text};
\node (stoffNach) [block, right=of haupt] {Box 3 text};
\node (pfeil1) at (-2,-1.5) [arrow,left] {Arrow 1};
\node (pfeil2) at (-2,-2.5) [arrow,left] {Arrow 2 text};
\node (pfeil0) at (-2,0) [arrow,left] {Arrow 3 longer text};
\node (neben) at (9.5,-0.5) [arrow,left,label=below:] {Text};
\node (hauptP) at (9.5,0.5) [arrow,left,label=above:] {Text};
\node (pfeil3) at (9.5,1.5) [arrow,left] {Text};
\node (pfeil4) at (9.5,2.5) [arrow,left] {Lorem, Ipsum, Dolor, Sit};

\draw[arr] (pfeil0.east) -- (stoffVor.west);
\draw[arr] (stoffVor.east) -- (haupt.west);
\draw[arr] (haupt.east) -- (stoffNach.west);
\draw[arr] (stoffNach.north) --  ++(0,0.5) node [auto, swap, yshift=6] {Text} -| ($ (stoffVor.east) + (0.25,0) $);
\draw[arr] (pfeil1.east) -| (stoffVor.240);
\draw[arr] (pfeil1.east) -| (haupt.240);
\draw[arr] (pfeil1.east) -| (stoffNach.240);
\draw[arr] (pfeil2.east) -| (stoffVor.300);
\draw[arr] (pfeil2.east) -| (haupt.300);
\draw[arr] (pfeil2.east) -| (stoffNach.300);
\draw[line] (haupt.150) |-  (pfeil4.west);
\draw[line] (haupt.30) |-  (pfeil3.west);
\draw[line] (stoffNach.350) -- ++ (0.25,0) -- ++ (0,-0.1) |- (neben.west);
\draw[line] (stoffNach.10) -- ++ (0.25,0) -- ++ (0, +0.1) |- (hauptP.west);

\end{tikzpicture}

\end{document}

enter image description here