4

enter image description hereI’m trying to draw a structure like that in Latex and I’m having a hard time. I know how to draw nodes using \node and how to draw arcs using \draw but I can’t connect the two.

Sandy G
  • 42,558
  • 5
    This is very confusing. What is the node package you're talking about? The output you provided is very straightforward in TikZ. What did you try yet? – SebGlav Apr 03 '22 at 14:33
  • I think you could pick one of the solution you received and accept it, now ;) – SebGlav Apr 03 '22 at 21:26

3 Answers3

9

In order to help you starting with TikZ, here's a quick solution that reproduce your hand drawn design. Feel free to adapt it.

In the future, please consider adding a minimal working example (MWE) that illustrates your problem, starting with \documentclass{...} and ending with \end{document}.

nodes on chain

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{chains}
\begin{document}
    \begin{tikzpicture}[
        start chain=going base right,
        node distance=2cm,
        every on chain/.append style=
            {draw = violet,
            circle,
            inner sep=0pt,
            minimum size=1cm,
            line width=1pt,
            font=\sffamily},
        myedge/.style={line width=1pt, violet}]
    \foreach \i in {1,...,6}
        \node[on chain] (\i) {\i};

    \foreach \i in {1,...,5}
        {
        \pgfmathtruncatemacro{\j}{\i+1}
        \draw[myedge] (\i) -- (\j);
        }

    \draw[myedge]   (1) to [out=90, in=0] ++(-2,3)
                    (2) to [out=90, in=180] ++(2,3)
                    (3) to [out=90, in=90, looseness=1.5] (4)
                    (5) to [out=90, in=180] ++(2,3);
\end{tikzpicture}

\end{document}

SebGlav
  • 19,186
  • Thank you so much. I'm new to latex and I didn't even know how to properly phrase my problem but that's exactly the structure I want. Thank you. – user267662 Apr 03 '22 at 16:11
  • Nice answer! +1 for start chain = going base right,! – Zarko Apr 03 '22 at 16:33
  • Where you find definition for start chain = going base right? I made some experiments with it but so far didn't find and diference to start chain = going right – Zarko Apr 03 '22 at 17:14
  • I found it a while ago in an example here on TeX-SX for a chain of rectangle split nodes with vertical split. This allowed nodes to be chained on the first split cell instead of the centers. Here it's useless. Try adding \node[on chain, text width=1cm] {NOW YOU KNOW}; right after your chain of nodes and you'll see. – SebGlav Apr 03 '22 at 17:36
  • 1
    @SebGlav, thank you very much. Unfortunately this option is not documented in documentation ... – Zarko Apr 03 '22 at 18:22
5

A wee bit variation of nice @SebGlaw answer:


\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{chains,
                positioning}

\begin{document} \begin{tikzpicture}[ node distance = 2cm, on grid, start chain = going right, % vertex/.style = {circle, draw = blue, thick, minimum size=1em, font=\sffamily, on chain, join = by arr}, arr/.style = {draw=blue, semithick},
] ] \foreach \i in {1,...,6} \node[vertex] (\i) {\i};

\draw[arr] (1) edge [out=90, in=0] ++(-2,3) (2) edge [out=90, in=180] ++( 2,3) (3) edge [out=90, in=90, min distance=15mm] (4) (5) edge [out=90, in=180] ++(2,3); \end{tikzpicture} \end{document}

enter image description here

Zarko
  • 296,517
5

Here is the way a beginner might approach this:

enter image description here

First, place the nodes at your desired coordinates using the \node command. Then use \draw to connect nodes as you wish. The to[out= , in=] describes the angle out and the angle in to get curved lines. Finally, ++(x,y) describes relative coordinates (right x, up y) from the node.

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[every node/.style={circle, draw=blue, thick, inner sep=5pt}] \node at (2,0)(A1){1}; \node at (4,0)(A2){2}; \node at (6,0)(A3){3}; \node at (8,0)(A4){4}; \node at (10,0)(A5){5}; \node at (12,0)(A6){6}; \draw[thick, blue] (A1)--(A2)--(A3)--(A4)--(A5)--(A6) (A3) to[out=90, in=90] (A4) (A1) to[out=90, in=0] ++(-1,2) (A2) to[out=90, in=180] ++(1,2) (A5) to[out=90, in=180] ++(1,2); \end{tikzpicture}

\end{document}

Sandy G
  • 42,558