# Best practice for control flow charts

I wanted to plot a flow chart graph which looks similar to this diagram:

that comes from this source.

1. Which package would be best for that?
2. I don't want to use pstricks
-

An example with pgf/tikZ just for your inspiration.

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.geometric}

\begin{document}
\begin{tikzpicture}[%
->,
shorten >=2pt,
>=stealth,
node distance=1cm,
noname/.style={%
ellipse,
minimum width=5em,
minimum height=3em,
draw
}
]
\node[noname] (1)                                             {1};
\node[noname] (2) [below=of 1]                                {2};
\node[noname] (4) [node distance=1cm and 3mm,below left=of 2] {4};
\node[noname] (3) [left=of 4]                                 {3};
\node[noname] (5) [below=of 4]                                {5};
\node[noname] (6) [node distance=2cm,right=of 5]              {6};

\path (1) edge                   node {} (2)
(2) edge                   node {} (3)
(2) edge                   node {} (4)
(2) edge                   node {} (6)
(3) edge                   node {} (5)
(4) edge                   node {} (5)
(5) edge [bend right=20pt] node {} (2);
\end{tikzpicture}
\end{document}


More examples in the according tikZ Example Gallery.

-
Thanks, this is exactly what I was searching for! –  beyeran Jan 16 '11 at 12:33
The empty nodes on edges are useless. Why? –  Leo Liu Jan 16 '11 at 12:46
@Leo: I added them just for the case that the connections need some labels later. But you are right. For simple connections they can be dropped. –  Thorsten Donig Jan 16 '11 at 12:50
Is there a way to make the circles to ellipsis? –  beyeran Jan 16 '11 at 16:57
See my edits above. –  Thorsten Donig Jan 16 '11 at 19:15

This doesn't need TeX. You can just use graphviz to draw such graph. Of course, many LaTeX packages like pstricks and tikz can draw these graph, but I think graphviz is still easier to use.

It seems an example copied from main page of graphviz will be useful. With graphviz we don't have to tell computer where the nodes are, only edges are needed.

digraph finite_state_machine {
rankdir=LR;
size="8,5"
node [shape = doublecircle]; LR_0 LR_3 LR_4 LR_8;
node [shape = circle];
LR_0 -> LR_2 [ label = "SS(B)" ];
LR_0 -> LR_1 [ label = "SS(S)" ];
LR_1 -> LR_3 [ label = "S(\$end)" ];
LR_2 -> LR_6 [ label = "SS(b)" ];
LR_2 -> LR_5 [ label = "SS(a)" ];
LR_2 -> LR_4 [ label = "S(A)" ];
LR_5 -> LR_7 [ label = "S(b)" ];
LR_5 -> LR_5 [ label = "S(a)" ];
LR_6 -> LR_6 [ label = "S(b)" ];
LR_6 -> LR_5 [ label = "S(a)" ];
LR_7 -> LR_8 [ label = "S(b)" ];
LR_7 -> LR_5 [ label = "S(a)" ];
LR_8 -> LR_6 [ label = "S(b)" ];
LR_8 -> LR_5 [ label = "S(a)" ];
}


-
Could you provide a complete example to make others comprehend how to include that in a LaTeX document? –  Thorsten Donig Jan 16 '11 at 13:04
graphviz is not a part of TeX. Just use \includegraphics to import the graph. –  Leo Liu Jan 16 '11 at 15:19
Thanks. In the meantime I discovered the graphvizzz package. –  Thorsten Donig Jan 17 '11 at 10:15
@Thorsten I have never use it but it should be useful. This dot2tex can convert xdot output from Graphviz to a series of PSTricks or PGF/TikZ commands –  S. Boonto Feb 26 '11 at 16:26

If you want to draw graph (graph theory) diagram, then PSTricks can do this easily.

See this tutorial.

-
I think answers on this site should be self-contained. Please add an example from the tutorial. –  Seamus Dec 17 '11 at 14:10
Great reference ! Thanks :D. –  Grzegorz Wierzowiecki Jan 6 '12 at 13:58