10

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.

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

2 Answers 2

10

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.

4
  • ty guys for the fast response :D
    – Bibtex
    Mar 23, 2012 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, 2012 at 17:35
  • @Fritz: Thanks, I forgot to remove that from my first attempt.
    – Caramdir
    Mar 23, 2012 at 17:43
  • What if I only want to affect an specific loop instead of affecting all loops (i.e. using every loop/.style)? Edit: I did it by drawing multiple loops by using multiple \draw commands and specifying [every loop/.style={}] after the \draw command that contains the loop which I want to be indirected. However, I wonder if it is necessary to use multiple \draw commands? Isn't there a way for setting the style of a given edge so that using [every loop/.style={}] is not necessary?
    – rdrg109
    Jun 28, 2021 at 7:51
5

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}  

enter image description here

2
  • 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) May 24, 2012 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 May 25, 2012 at 5:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .