# How to get started with drawing this flow chart in TikZ?

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:

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}


-
Once you get the hang of it, it can become a love story... :) – Count Zero Oct 8 '11 at 12:13
Surely can, but the beginning can be frustrating ;) the results look stunning for the major part! – Ingo Oct 8 '11 at 12:46
Something like (box1.260) means a point in the border of box1 node at an angle of 260 degrees. Another option is ([xshift=-5mm]box1.south). I'm sorry but I have no tikz at hand to test and provide a better answer. – Ignasi Oct 8 '11 at 13:17
What do you mean by "align arrows by their tips"? Also, particularly given that you have accepted an answer to the original question, it's best to ask follow-up questions as fresh questions (link back to the original, of course). That way, it's clear what the new question is. – Andrew Stacey Oct 17 '11 at 18:57
I agree with @AndrewStacey and also kudos for the distance you have covered. – percusse Oct 17 '11 at 19:15

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}


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}


-
your minimum example can be simplified and calc-free, with \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}  – percusse Oct 8 '11 at 15:20
I think it is too much right now to go into calc library from the beginning. That's why I have given the above code. Hope you don't mind. – percusse Oct 8 '11 at 15:21
Aah, the intersection notation. Nice solution, I didn't think of that. Of cause I don't mind. The interesting thing about such questions is that usually there are multiple ways, and to be honest, I like your approach better – Tom Bombadil Oct 8 '11 at 15:58
Thanks for the great hints, that really got me started! I'll post the final result once I'm done. – Ingo Oct 9 '11 at 10:22
Hey Tom, in the meantime I got busy and produced some output. In case you can help me on my last issue, I'd be really glad. Still accepting as accept now, as it solved my problem for 90% at least ;) – Ingo Oct 17 '11 at 18:38
show 1 more comment

One way to go - according to this answer - would be to save your diagram as a PDF file (this preserves the programmatic information on how to draw the figures), get Inkscape (free), import into Inkscape (don't worry if it takes awhile until it's done) and then using this plug-in, convert to TikZ. I have tried it, it should work well. Good luck! :)

-
 I'll give it a shot! But let's suppose I want to learn coding TikZ. Using which features would you implement the diagram? – Ingo Oct 8 '11 at 12:48 For starters you could check the code generated from exporting from Inkscape, then you could consider grouping elements together into more complex shapes and try to clean up/shorten the code that Inkscape spewed out. – Count Zero Oct 8 '11 at 14:07 @ Count Zero - Regrettably, the workflow you propose doesn't make much sense. The point of the inkscape2tikz plugin is to convert the SVG code of a vector graphic to TikZ code. Importing a BMP or PNG of the chart into inkscape would simply result in an embedded bitmap, with no information on how to programmatically draw that chart. This said, the OP could certainly draw the chart in inkscape using the tools therein and then convert to TikZ. – Richard Terrett Oct 8 '11 at 14:47 @Richard Terrett: well seems Inkscape doesn't convert bitmap images into vector graphics... that's a shame. :( Edited my answer to work around that. – Count Zero Oct 8 '11 at 15:13