2

I am writing many small graphs, using TikZ's graphs library, which often include loops. I do not like the way the default loop left or loop right options look, so I have made my own style, called ll here.

That is fine, but when I provide a label using the quotes syntax, I have to manually place it, which isn't necessary with loop left. How can I specify in the preamble where labels should be placed?

Update: Gonzalo Medina's answer puts the labels on the proper side. I would also like them to be closer to the edge, like when I use left=-2pt in the code below. Is that possible?

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{graphs}
\usetikzlibrary{quotes}

\tikzset{ll/.style={in=210,out=150,distance=3mm},
dot/.style={circle,fill,inner sep=2pt}}

\begin{document}

\tikz \graph {a/[dot] --[ll,"1" left=-2pt] a};  What I want to see.

\tikz \graph {a/[dot] --[ll,"1"] a};  What I want to type.

\tikz \graph {a/[dot] --[loop left,"1"] a};  The `loop left' option ``knows'' what to do.

\end{document}

Loops

2

I suggest a different definition of the ll adjusting the in and out values:

enter image description here

The code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs}
\usetikzlibrary{quotes}

%\tikzset{
%  ll/.style={
%    in=210,
%    out=150,
%    distance=3mm,
%    looseness=8
%    },
%}

\makeatletter
\tikzset{
  ll/.style={
    in=150,
    out=210,
    loop,
    min distance=3mm,
    every node/.append style={inner xsep=1pt}
  },
  dot/.style={circle,fill,inner sep=2pt}
}
\makeatother

\begin{document}

\tikz \graph {a/[dot] --[ll,"1"] a};  What I get with the \texttt{ll}a style.

\tikz \graph {a/[dot] --[loop left,"1"] a};  The \texttt{loop left} option ``knows'' what to do.

\end{document}
  • You are right: swapping the "in" and "out" parameters results in the label on the left side. Thanks! Ideally, I could also have the labels placed closer to the loop (as with left=-2pt.) – Nick Matteo Dec 7 '14 at 4:25
  • @Kundor Please see my updated answer. – Gonzalo Medina Dec 7 '14 at 5:10
  • Thanks, that works. (I ended up going with inner xsep=.1111em, and inner ysep=.2666em for the analogous up- and down-loops. – Nick Matteo Dec 7 '14 at 20:06

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.