How could I create this graph? Assume that there are weights from every node to all directions. Apologies for the badly drawn example and thank you in advance for your help!
Asked
Active
Viewed 275 times
1 Answers
5
The proper way is to use the graph drawing libraries that come with TikZ, the quick and dirty way is to draw it in a loop. If you want more information on the proper way, show us what you have tried. Here is the quick and dirty way (but the arc arrow may be useful for the proper way, too).
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,bending,decorations.markings}
\tikzset{% https://tex.stackexchange.com/a/430239
arc arrow/.style args={%
to pos #1 with length #2}{
decoration={
markings,
mark=at position 0 with {\pgfextra{%
\pgfmathsetmacro{\tmpArrowTime}{#2/(\pgfdecoratedpathlength)}
\xdef\tmpArrowTime{\tmpArrowTime}}},
mark=at position {#1-\tmpArrowTime} with {\coordinate(@1);},
mark=at position {#1-2*\tmpArrowTime/3} with {\coordinate(@2);},
mark=at position {#1-\tmpArrowTime/3} with {\coordinate(@3);},
mark=at position {#1} with {\coordinate(@4);
\draw[-{Stealth[length=#2,bend]}]
(@1) .. controls (@2) and (@3) .. (@4);},
},
postaction=decorate,
}
}
\begin{document}
\begin{tikzpicture}[bullet/.style={fill,circle,inner sep=2pt},
bent arrow/.style={arc arrow=to pos #1 with length 2mm}]
\path foreach \X in {1,...,5} {
(-72+90+72*\X:3) node[bullet] (p\X){}};
\foreach \X [evaluate=\X as \NextX using {int(mod(\X,5)+1)},
evaluate=\X as \NextNextX using {int(mod(\X+1,5)+1)},] in {1,...,5} {
\draw[bent arrow=0.55] (p\X) to[out=-72+110+72*\X,in=-72+180+72*\X]
++ (-72+90+72*\X:1.25) to[out=-72+72*\X,in=-72+70+72*\X] (p\X);
\draw[bent arrow=0.55] (p\X) to[out=-72+180+72*\X,in=72*\X,looseness=0.8] (p\NextX);
\draw[bent arrow=0.55] (p\NextX) to (p\X);
\draw[bent arrow=0.35] (p\NextNextX) to (p\X);
\draw[bent arrow=0.35] (p\X) to (p\NextNextX);}
\end{tikzpicture}
\end{document}


midwaydoesn't actually place it in the visual middle, use\node[pos=.4] {text}or some other number between 0 and 1 , instead of 0.4 (midwayis the same aspos=.5). Now this may overlap the label and the arrow, so use something like\node[pos=.4,above=10pt] {text}or similar to fine-tune the position of the label. – Jānis Lazovskis Sep 08 '19 at 09:27