I'm working on creating flowcharts directly inside LaTeX documents using tikz. I am admittedly an extreme novice with tikz, although I have quite a bit of experience using LaTeX.
My problem is when trying to show an endless loop with the flowchart, i.e., an edge or path that starts and ends at the same node.
For example,
is an example of what I want (right) and what I'm getting (left) using the following LaTeX code:
\usetikzlibrary{shapes.geometric,arrows}
\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 badly centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [ draw, -latex']
\tikzstyle{terminator} = [ draw, ellipse, fill=red!20, node distance=3cm, minimum height=2em]
\begin{tikzpicture}[node distance=2cm, auto]
\node [terminator] (puc) {Power-Up Reset};
\node [block, below of=puc] (wdt) {Stop Watchdog};
\node [block, below of=wdt] (port) {Setup Port Pins};
\node [block, below of=port] (loop) {Loop Forever};
\path [line] (puc) -- (wdt);
\path [line] (wdt) -- (port);
\path [line] (port) -- (loop);
\path [line] (loop) -- (loop);
\end{tikzpicture}
I assume I'm going to need something a bit more complex.
Best Answer
Simply change
\path [line] (loop) -- (loop);
to\path [line] (loop) edge[loop right] ();
(orloop below
orloop left
).Alternatively, change it to
\path [line] (loop) |- ($(loop.south east) + (0.5,-0.5)$) |- (loop);
(with\usetikzlibrary{calc}
) forFurther, adding
rounded corners
(e.g.\path [line,rounded corners] (loop) |- ($(loop.south east) + (0.5,-0.5)$) |- (loop);
) gives