0

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}
  • 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 5:30
3

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.