2

I want to draw this image with TikZ:

enter image description here

I write this code:

\documentclass{standalone}

\usepackage{amsmath,amsfonts,amssymb,amsthm}

\usepackage{tikz}

\usetikzlibrary{decorations.pathreplacing,decorations.markings}
\usetikzlibrary{arrows,automata}
\usetikzlibrary{calc}



\tikzset{dot/.style = 
{circle,
draw=blue,
line width=.5pt},
dot/.default = 4pt
}

\tikzset{
  % style to apply some styles to each segment of a path
  on each segment/.style={
    decorate,
    decoration={
      show path construction,
      moveto code={},
      lineto code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
      curveto code={
        \path [#1] (\tikzinputsegmentfirst)
        .. controls
        (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
        ..
        (\tikzinputsegmentlast);
      },
      closepath code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
    },
  },
  % style to add an arrow in the middle of a path
  mid arrow/.style={postaction={decorate,decoration={
        markings,
        mark=at position .5 with {\arrow[scale=1.5,#1]{stealth}}
      }}},
}

\begin{document}

\begin{tikzpicture}[line cap=round]

  % First, define nodes
  \draw (0, 0) node[
                            inner sep=0pt,
                            fill=black,
                            label={left:{$\boldsymbol{M}$}}
                            ] (M) {};  
  \draw (2, -2) node[
                            inner sep=0pt,
                            fill=black,
                            label={above:{$\boldsymbol{Q}$}}
                            ] (Q) {};  
  \draw (5, -1) node[
                            inner sep=0pt,
                            fill=black,
                            label={above:{$\boldsymbol{P}$}}
                            ] (P) {}; 
  \draw (4, 1.5) node[
                            inner sep=0pt,
                            fill=black,
                            label={right:{$\boldsymbol{O}$}}
                            ] (O) {}; 
  \draw (1, 1.5) node[
                            inner sep=0pt,
                            fill=black,
                            label={above:{$\boldsymbol{N}$}}
                            ] (N) {}; 

  % Draw curved path
  \path [very thick, draw=black, postaction={very thick, on each segment={mid arrow=black}}]
  (M) to [bend left=100] (N)
  (M) to [bend left=40] (N)
  (M) -- (N)
  (M) to [bend right=40] (N)
  (M) to [bend right=100] (N);

\end{tikzpicture}

\end{document}

result (without red circle): enter image description here

As specified by the circle, the primary and endpoint of the edges are not similar to the shape. Is there an easier and better way to do this?

5
  • You can use e.g. out=40, in=140 to specify the angles the path takes out and in. Or you can use controls which are similar to the little handles you see in graphical programmes such as Inkscape. There are also third-party packages such as hobby, though I'm not sure you want that here. But the shapes you've circled look pretty similar to me: am I looking at the wrong thing?
    – cfr
    Nov 7, 2023 at 6:22
  • Why are you drawing 5 curves as a single path? Is there some special reason for that? It just doesn't strike me as an obvious thing to do here.
    – cfr
    Nov 7, 2023 at 6:25
  • 1
    Or do you mean they don't look as they look in your drawn diagram? I read your question as saying the shapes at M and N looked different, but maybe that's a misinterpretation ....
    – cfr
    Nov 7, 2023 at 6:33
  • If you based this code on an existing source, can you provide a link?
    – cfr
    Nov 7, 2023 at 6:46
  • This reminds me. Nov 7, 2023 at 8:34

2 Answers 2

1

I must confess that I was lost in your MWE, so I decide to write it from scratch so, that it is as similar as possible to provided sketch. However, the code of image is much simpler and shorter (at least to my opinion) and image is nicer (again according to my taste):

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                decorations.markings,
                ext.arrows,    % defined in the tikz-ext package 
                positioning}

\tikzset{dot/.style = {circle, fill, thick, inner sep=2pt, outer sep=0pt,
                       node contents={} },
  every edge/.style = {draw, thick,  
                       decoration={markings,
                                   mark=at position 0.5 with {\arrow[very thick,scale=0.6] {Centered Straight Barb}}
                                 },
                        postaction={decorate},
                       },
 every label/.style = {anchor=center, label distance = 1.7ex},
         bend angle = 25
        }% end of tikzset

\begin{document}
    \begin{tikzpicture}
% First, define nodes
\foreach \i [count=\j from 0] in {M,Q,P,O,N}
    \path (0,0) -- (180+\j*72:2) node[label=180+\j*72:\i] (\i) [dot];
% Draw curved arrows
\draw
  (M) edge [bend  left=55] (N)
  (M) edge [bend  left] (N)
  (M) edge (N)
  (M) edge [bend right] (N)
  (M) edge [bend right=55] (N);
\draw
  (N) edge [bend  left] (O)
  (N) edge [bend right] (O);
\draw
  (O) edge [bend  left=55] (P)
  (O) edge [bend  left] (P)
  (O) edge [bend right] (P)
  (O) edge [bend right=55] (P);
\draw
  (M) edge [bend  left] (Q)
  (M) edge (Q)
  (M) edge [bend right] (Q);
\draw
  (Q) edge [bend  left] (P)
  (Q) edge (P)
  (Q) edge [bend right] (P);
\end{tikzpicture}
\end{document}

enter image description here

1

Not sure if this is what you mean, so very quickly, you can specify curves in other ways.

% Draw curved path
  \path [very thick, draw=black, postaction={very thick, on each segment={mid arrow=black}}]
  (M) .. controls +(-1.25,1) and +(-1,1) .. (N)
  (M) to [bend left=40] (N)
  (M) -- (N)
  (M) to [bend right=40] (N)
  (M)  .. controls +(1,-1) and +(1.25,-1) .. (N);

more curvy curves

You must log in to answer this question.

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