Self-loop with tikz-graphdrawing library

Self-loop can be drawn on a node; there are plenty of examples in documentation e.g. tikz: self loop with two arrows at the end (i.e. ending by ->>).

I can achieve it via graphviz easily.

I am using tikz-graphdrawing library and I want to draw a self-loop on a node. I tried the following

\tikz \graph[ layered layout ] { {1,2} -- n -- n -- {3,4}; };


And

\tikz \graph[ layered layout ] { {1,2} -- n[loop] -- {3,4}; };


MWE

% Compile using lualatex --shell-escape
\RequirePackage{luatex85}
\documentclass[crop,tikz]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing}
\usegdlibrary{layered}

\begin{document}

\tikz \graph[ layered layout ] { {1,2} -- n -- n -- {3,4}; };

\tikz \graph[ layered layout ] { {1,2} -- n[loop] -- {3,4}; };

\end{document}

• Also you should go back to all your old questions which the community answered for you and accept the best answers. Jun 17 '17 at 5:30

1 Answer

You were almost there.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing}
\usegdlibrary{layered}
\begin{document}
\tikz[every loop/.style={}] \graph[layered layout] { {1,2} -- n --[loop right] n -- {3,4}; };
\end{document}


• Is there a way to make self-loop without arrow-head? I tried usually style [--,loop right] which did not work. Jun 18 '17 at 9:25
• Found solution to remove arrowhead head: tex.stackexchange.com/questions/49149/… Jun 19 '17 at 4:40
• @Dilawar Glad you found it :) Sorry for not responding. Jun 19 '17 at 5:24