# Close a cycle in a TikZ graph with a loop

Consider the following simple flow diagram. I like using the graph drawing library in TikZ for its simplicity and semantics:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{graphdrawing}
\usegdlibrary{trees}

\begin{document}

\tikz[>=latex]
\graph[
tree layout,
node pre sep = 0.2em,
grow=right,
},
]
{
A -> B -> C -> D -> E -> (A.south)
};

\end{document}


This code connects an arrow from E.west to A.south that crosses the other nodes. How can I create a loop that leaves E.south or E.east and then goes downwards to enter A.south or maybe A.west in the end again?

• The code does not compile. – mvkorpel Jul 10 '14 at 9:40

Three options:

\documentclass[border=6pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing}
\usegdlibrary{trees}

\begin{document}

\begin{tikzpicture}[>=latex]
\graph[
tree layout,
node pre sep = 0.2em,
grow=right,
]
{
A -> B -> C -> D -> E ->[bend left] A
};
\begin{tikzpicture}[>=latex]
\graph[
tree layout,
node pre sep = 0.2em,
grow=right,
]
{
A -> B -> C -> D -> E ->[out=-90,in=-90] A
};
\begin{tikzpicture}[>=latex]
\graph[
tree layout,
node pre sep = 0.2em,
grow=right,
]
{[name=str]
A -> B -> C -> D -> E
};
\draw[-] (str E.east) to[out=0,in=0] ([yshift=-15pt]str C);
\draw[<-] (str A.west) to[out=180,in=180] ([yshift=-15pt]str C);
\end{tikzpicture}

\end{document}


The first two options use the fact that you can use the ->[...] syntax to modify the path; the third option uses the [name=<string>] prefix for the graph nodes and then two appropriate \draw commands.