# Self loop in an undirected graph using TikZ

How can I create a self loop without a direction on the edge?

\path[every node/.style={font=\sffamily\small}]
(3)   edge[loop] node  {$e_{1}$} (3);


creates the loop I want but has a direction.

-
For the latest version of tikz, this can be done simply with \Loop[style={}](A). –  user33585 Jul 12 '13 at 23:36

For some reason, the TikZ every loop style contains an arrow. So you simple have to remove that:

\begin{tikzpicture}[every loop/.style={}]
\node (3) {(3)};
\path[every node/.style={font=\sffamily\small}]
(3)   edge[loop] node  {$e_{1}$} (3);
\end{tikzpicture}


or remove it globally with

\tikzset{every loop/.style={}}


in the preamble.

-
ty guys for the fast response :D –  Bibtex Mar 23 '12 at 17:32
In fact you don't even need the extra ,- on the edge. edge[loop] will suffice if you cleared the every loop style. –  Fritz Mar 23 '12 at 17:35
@Fritz: Thanks, I forgot to remove that from my first attempt. –  Caramdir Mar 23 '12 at 17:43

There is another possibility. loop and every loop are simple styles and it's possible to redefine loop instead of every loop. It's interesting if you have a lot of loops and if you want some specific options

The code from pgf

% Loops

\tikzstyle{loop}=                    [to path={
\pgfextra{\let\tikztotarget=\tikztostart}
[looseness=8,min distance=5mm,every loop]
\tikz@to@curve@path
}]

\tikzstyle{every loop}=              [->,shorten >=1pt]


My modification

\documentclass{article}
\usepackage{tikz}
\makeatletter
\tikzset{my loop/.style =  {to path={
\pgfextra{\let\tikztotarget=\tikztostart}
[looseness=12,min distance=10mm]
\tikz@to@curve@path},font=\sffamily\small
}}
\makeatletter

\begin{document}
\begin{tikzpicture}
\node (3) {(3)} ;
\path  (3)   edge[my loop] node[above]  {$e_{1}$} (3);
\end{tikzpicture}

\end{document}


-
nice, can I ask how you would let the loop spurt out on a different direction? (usually I use the grow=left option, but it doesn't seem to work) –  donkey kong May 24 '12 at 22:36
You need to modify some styles like \tikzstyle{loop left}= [right,out=15,in=-15,my loop] . You need to change loop left with my loop left and 'loop' with my loop. Another possibility is to modify and to keep the names loopand loop left –  Alain Matthes May 25 '12 at 5:22
thanks for that –  donkey kong May 25 '12 at 20:00