7

I'm a beginner of latex and tikz. I want to have curved arrows on top of each node as in tikx example.

Following is my code.

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

\begin{figure}[h]
\centering
\begin{tikzpicture}
  [scale=.8,auto=left,every node/.style={circle,fill=blue!20}]


  \node (n1) at (9,8) {1};
  \node (n2) at (6,7) {2};
  \node (n3) at (5,5)  {3};
  \node (n4) at (6,3) {4};
  \node (n5) at (9,2)  {5};
  \node (n6) at (12,3)  {6};
  \node (n7) at (13,5)  {7};
  \node (n8) at (12,7)  {8};


  \foreach \from/\to in {n1/n2,n2/n3,n3/n4,n4/n5,n5/n6,n6/n7,n7/n8,n8/n1,n1/n3,n1/n4,n1/n5,n1/n6,n1/n7,n2/n4,n2/n5,n2/n6,n2/n7,n2/n8,n3/n5,n3/n6,n3/n7,n3/n8,n4/n6,n4/n7,n4/n8,n5/n7,n5/n8,n6/n8}
    \draw (\from) -- (\to);

\end{tikzpicture}
\end{figure}

\end{document}

How to draw curved arrows on top of every node?

3 Answers3

9
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}

\begin{figure}[h]
\centering
\begin{tikzpicture}
  [scale=.8,auto=left,every node/.style={circle,fill=blue!20}]


  \node (n1) at (9,8) {1} edge [in=100,out=80,loop] ();
  \node (n2) at (6,7) {2} edge [in=150,out=130,loop] ();
  \node (n3) at (5,5)  {3} edge [in=190,out=170,loop] ();
  \node (n4) at (6,3) {4} edge [in=240,out=220,loop] ();
  \node (n5) at (9,2)  {5} edge [in=280,out=260,loop] ();
  \node (n6) at (12,3)  {6} edge [in=330,out=310,loop] ();
  \node (n7) at (13,5)  {7} edge [in=10,out=350,loop] ();
  \node (n8) at (12,7)  {8} edge [in=60,out=40,loop] ();


  \foreach \from/\to in {n1/n2,n2/n3,n3/n4,n4/n5,n5/n6,n6/n7,n7/n8,n8/n1,n1/n3,n1/n4,n1/n5,n1/n6,n1/n7,n2/n4,n2/n5,n2/n6,n2/n7,n2/n8,n3/n5,n3/n6,n3/n7,n3/n8,n4/n6,n4/n7,n4/n8,n5/n7,n5/n8,n6/n8}
    \draw (\from) -- (\to);

\end{tikzpicture}
\end{figure}

\end{document}

enter image description here

6

If you are happy with circular placement things get pretty simplified with foreach loops for n>4 nodes. Then you need to tweak the loop drawing which is also possible but I got a little bored :P

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}\def\myn{9}
\foreach \x in {1,...,\myn}{\node[circle,fill=blue!20,inner sep=1pt] (n\x) at ({(\x-1)*360/\myn+90}:2cm) {\x};}
\foreach \x[evaluate={\xi=(\x-1)*360/\myn+90+360/\myn;\xo=\xi-360/(0.5*\myn)}] in {1,...,\myn}{
\foreach \y in {\x,...,\myn}{\ifnum\x=\y\path (n\x)edge [in=\xi,out=\xo,loop] ();\else\draw[-](n\x) -- (n\y);\fi}}
\end{tikzpicture}
\end{document}

For n=9

enter image description here

For n=40.... (I really don't know why)

enter image description here

percusse
  • 157,807
2

Maybe something like this?

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{arrows}
\begin{document}

\begin{tikzpicture}
  [scale=.8,auto=left,every node/.style={circle,fill=blue!20}]


  \node (n1) at (9,8) {1};
  \node (n2) at (6,7) {2};
  \node (n3) at (5,5)  {3};
  \node (n4) at (6,3) {4};
  \node (n5) at (9,2)  {5};
  \node (n6) at (12,3)  {6};
  \node (n7) at (13,5)  {7};
  \node (n8) at (12,7)  {8};


  \foreach \from/\to in {n1/n2,n2/n3,n3/n4,n4/n5,n5/n6,n6/n7,n7/n8,n8/n1,n1/n3,n1/n4,n1/n5,n1/n6,n1/n7,n2/n4,n2/n5,n2/n6,n2/n7,n2/n8,n3/n5,n3/n6,n3/n7,n3/n8,n4/n6,n4/n7,n4/n8,n5/n7,n5/n8,n6/n8}
    \draw (\from) -- (\to);

  \foreach \i in {1,...,8}
      \draw [->] (n\i.north west) [out=45, in=135] to (n\i.north east);

\end{tikzpicture}

\end{document}

network with curved arrows

cfr
  • 198,882