2

I'm trying to draw a graph in TikZ with different-looking loops.

In the graph below, I would like to make one loop smaller and the other larger. I would also like to be able to control the shape or roundness of the loops.

The parameter "looseness" doesn't seem to do anything. Perhaps it is possible to use control points? I've been trying to draw a loop manually, without actually using "loop", but cannot get it to work when the starting and ending points are identical.

After reading this question I'm able to change size for both loops at once. The answer mentions that this is possible to do for individual loops with ".style", but not exactly how. (There's also a reference to a section in the TikZ documentation for more detail. I have looked here at 74.4, but didn't find any answers.)

Here's my code and the current output:

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[every loop/.style={min distance=30mm}]

\draw[thick] (0,0) to [out=-30,in=-150, loop] (0,0) -- (0,1);

\draw[thick] (0,1) to [out=30, in=150, loop] (0,1);

\end{tikzpicture} \end{document}

enter image description here

Lorents
  • 170

2 Answers2

5

To modify each loop individually, just change the style in the object options, like this:

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[every loop/.style={min distance=30mm}]

\draw[thick] (0,0) to [out=-20,in=-150, loop, style={min distance=12mm}] (0,0) -- (0,1);

\draw[thick] (0,1) to [out=30, in=150, loop] (0,1);

\end{tikzpicture} \end{document}

First image

Now, for the "roundness" of each loop, I wonder if two circles would better fit your goal:

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[every loop/.style={min distance=30mm}]

\draw[thick] (0,-0.5) circle (0.5);
\draw[thick] (0,0) -- (0,1);
\draw[thick] (0,1.5) circle (0.5);

\end{tikzpicture} \end{document}

Second image

  • 1
    Thanks! I considered circles, but thought that one could perhaps more flexibly modify the shape by changing "looseness" or with control points. I will make a slight edit to my question (and also fix the asymmetry in the code for the lower loop). – Lorents Feb 11 '23 at 19:23
4

Here's a bit to help you with control points of Bezier curves:

different size loops

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}

\newcommand{\dist}{3}
\draw[thick]    (0,0) .. controls ++ (2*\dist,-\dist) and ++ (-2*\dist,-\dist) .. (0,0)
                --
                (0,1) .. controls ++ (\dist,\dist) and ++ (-\dist,\dist) .. (0,1);

\end{tikzpicture} \end{document}

Here I used a variable distance \dist to help you tr some values, but you can choose whatever value you need.

Know that I used ++ in order to define the control points relatively to the anchor points and not in absolute coordinates, where ++ would not be needed.

Lorents
  • 170
SebGlav
  • 19,186