3

Note: I posted this question on math stack exchange and it was suggested I repost here.

I usually use geogebra for drawing images for papers. However as far as I am aware, one can draw straight lines and arcs, but nothing more complicated (not without a lot of faffing around and trial and error anyway). I am trying to recreate an image similar to the one below. If anyone knows what package was likely used to draw this, I would be very grateful! Or any other suggestions would be great. Someone in the math Se post suggested tikz. I haven't used this on its own before, and am looking at the tutorial and manual, but I'm still not seeing how to use it to make the non-overlapping curved lines between the middle-layer vertices shown below.

enter image description here

4
  • This is quite easy: First draw the nodes with \node[circle] (nodeA) at (x,y) {}, then you can connect these nodes with draw macros, e.g. using \draw[blue] (nodeA) to[bend right] (nodeB);. Commented Jul 26, 2022 at 19:57
  • I would use a package with which I'm most familiar. From your selection of tags I assume that you should use `tikz˙. An example of it use is given in @JasperHabicht comment.
    – Zarko
    Commented Jul 26, 2022 at 20:03
  • Sorry, yes. My example would require TikZ. Commented Jul 26, 2022 at 20:23
  • @JasperHabicht Thank you for your reply! This looks promising and I am trying to figure out how to do it. But I am new to tikz. Could you explain why you have used "\node" rather than "\draw circle". Also is "(node A)" the label? If so, what goes in the brackets "{}" at the end? A link to a relevant documentation would be okay as well if this is a lot to explain. I'm just not really understanding the official documentation for 'nodes and edges' here: tikz.dev/tikz-shapes
    – Meep
    Commented Jul 26, 2022 at 20:24

1 Answer 1

7

Okay, let me give you a very basic introduction to TikZ. You should take a loot at the TikZ manual which contains a few very insightful tutorials.

Two very important macros in TikZ are \node and \draw. With \node you can place nodes at coordinates, with \draw you can draw lines between nodes or coordinates. Nodes typically have some contents, for example a node can contain a letter that is placed inside a circle. You can name nodes and refer to these names later in your code. In your example, the nodes do not contain anything. They just are represented by small circles that have labels.

Almost everything in TikZ can have options that are used for styling. You can use scopes if you need to apply these options to multiple items at once.

You can use the label option to append a label to a node. The option gets a value of which the first part denotes the position of the label and the second the contents of the label, both parts being split by a colon. The position is given in degrees around the center of the node, starting from the right side of the node and going counterclockwise. For example label={90:Hello} would print the text Hello above the node.

Some options, such as bend left or bend right, can take a value, but they are also happy without. Depending on the value, the line is bend more or less. The options in and out take degree-based positions (similar to the label option) to denote where the connecting line goes out and where it goes in (to the next node). The options bend left, bend right, in and out are nice ways to bend lines. You can append these options to the edge between two nodes or coordinates.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}

    % step 1: draw the nodes
    
    \begin{scope}[every node/.style={circle, draw, inner sep=2pt}]
    
        %     v options         v name     v coordinate  v contents (here: empty)
        \node[label={0:$v_1$}] (v1)    at (0,0)         {};
        
        \node[label={0:$v_2$}] (v2) at (2,0) {};
        \node[label={180:$v_3$}] (v3) at (4,0) {};
        
        \node[label={0:$v_{n-1}$}] (v8) at (8,0) {};
        \node[label={0:$v_{n}$}] (v9) at (10,0) {};
    
        \node[label={90:$u_{1}$}] (u1) at (5,2.5) {};    
        \node[label={270:$u_{2}$}] (u2) at (5,-2.5) {};
    
    \end{scope}
    
    % step 2: draw the lines
    
    \begin{scope}[thick]
    
        %     v options                                      v from  v to
        \draw[loosely dotted, shorten >=5pt, shorten <=5pt] (v3) -- (v8);
        
        \draw[green] (u1) to[out=180, in=90] (v1);
        \draw[green] (u2) to[out=180, in=270] (v1);

        \draw[red] (u1) to[out=0, in=90] (v9);

        \draw[red] (u1) to[bend right=20] (v1);
        \draw[red] (u1) to[bend right] (v2);
        \draw[red] (u1) to[bend right=10] (v2);
        \draw[red] (u1) to[bend left] (v3);
        \draw[red] (u1) to[bend left] (v8);

        \draw[red] (v1) to[bend left=50] (v2);
        \draw[red] (v2) to[bend left=50] (v3);
        \draw[red] (v8) to[bend left=50] (v9);

        \draw[blue] (u2) to[out=0, in=270] (v9);

        \draw[blue] (u2) to[bend left=20] (v1);
        \draw[blue] (u2) to[bend left] (v2);
        \draw[blue] (u2) to[bend left=10] (v2);
        \draw[blue] (u2) to[bend right] (v3);
        \draw[blue] (u2) to[bend right] (v8);

        \draw[blue] (v1) to[bend right=50] (v2);
        \draw[blue] (v2) to[bend right=50] (v3);
        \draw[blue] (v8) to[bend right=50] (v9);

    \end{scope}
    
\end{tikzpicture}

\end{document}

enter image description here

1
  • 1
    This is amazingly useful! Thank you! I'm going through it in detail to understand it now
    – Meep
    Commented Jul 26, 2022 at 21:07

You must log in to answer this question.

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