2

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}; };

enter image description here

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}
Dilawar
  • 992
  • 3
    Also you should go back to all your old questions which the community answered for you and accept the best answers. – Henri Menke Jun 17 '17 at 05:30

1 Answers1

4

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}

enter image description here

Henri Menke
  • 109,596