如何使用 tikz 包绘制有向图?

如何使用 tikz 包绘制有向图?

我想要绘制下图:

在此处输入图片描述

目前我的工作内容如下:

\documentclass{article}

\usepackage{tikz,subcaption,amsmath}

\usetikzlibrary{arrows.meta,positioning}

\begin{document}

\begin{tikzpicture}
\centering
\coordinate (a) at (0,0);
\coordinate (b) at (3,0);
\coordinate (c) at (5,-2);
\coordinate (d) at (3,-4);
\coordinate (e) at (1.5,-4);
\coordinate (f) at (0,-4);
\coordinate (g) at (-2,-2);

\draw (a) node[above]{$v_1$};
\draw (b) node[above]{$v_2$};
\draw (c) node[right]{$v_3$};
\draw (d) node[below]{$v_4$};
\draw (f) node[below]{$v_{n-1}$};
\draw (g) node[left]{$v_{n}$};

\draw [fill=black] (a) circle[radius=2pt];
\draw [fill=black] (b) circle[radius=2pt];
\draw [fill=black] (c) circle[radius=2pt];
\draw [fill=black] (d) circle[radius=2pt];
\draw [fill=black] (e) circle[radius=2pt];
\draw [fill=black] (f) circle[radius=2pt];
\draw [fill=black] (g) circle[radius=2pt];

\draw [-{Latex[length=3mm]}] (a)--(b) ;
\draw [-{Latex[length=3mm]}] (b)--(c) ;
\draw [-{Latex[length=3mm]}] (c)--(d) ;
\draw [-{Latex[length=3mm]}] (d)--(e) ;
\draw [-{Latex[length=3mm]}] (e)--(f) ;
\draw [-{Latex[length=3mm]}] (f)--(g) ;
\end{tikzpicture} 

\end{document}

产生:

在此处输入图片描述

请帮忙。

答案1

这主要是带有极坐标和一些附加项的一个循环。整体大小由“函数”控制R=3;

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,bending,quotes}
\begin{document}
\begin{tikzpicture}[>={Stealth[bend]},dot/.style={circle,fill,inner sep=2pt},
    declare function={R=3;},bend angle=12]
 \path[dash pattern=on 1.5pt off 1pt] 
 (0,0) node[circle, inner sep=4pt,draw,
    label={[gray,font=\sffamily]above right:impurities}] (O){}
 foreach \X [count=\Y] in {1,2,3,4,n-1,n}
 {(180-\Y*60:R) node[dot,label={180-\Y*60:$v_{\X}$}] 
 (v\X){}
 (O) edge[bend left,->] (v\X)
 (v\X) edge[bend left,->] (O)
 \ifnum\Y>1
  \ifnum\Y<5
   (v\the\numexpr\Y-1) edge[solid,->,"$e_{\the\numexpr\Y-1}$"] (v\Y)
  \fi
 \fi
 }
  (0,{-R*cos(30)}) node[dot,label=-90:$\cdots$] (v0) {} 
 (O) edge[bend left,->] (v0)
 (v0) edge[bend left,->] (O) 
 ;
 \path[->] (vn) edge[bend left,"$e_{n}$"] (O)
 (v4) edge["$e_4$"] (v0)
 (v0) edge["$\cdots$"] (vn-1)
 (vn-1) edge["$e_{n-1}$"] (vn);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容