我是 Tikz 的新手,我正在尝试了解如何绘制图形,我的尝试是:
\documentclass[11pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[y=.4cm, x=.4cm,font=\normalsize]
\draw (0,5) -- (1,2);
\draw (1,2) -- (2.3,0.42) ;
\draw (5,0) -- (2.3,0.42) ;
\draw (9,2) -- (10,5);
\draw (7.3,9.4) -- (5,10);
\draw (9,8) -- (7.3,9.4);
\draw (10,5) -- (9,8);
\draw (5,10) -- (2.3,9.4);
\draw (0,5) -- (0.7,7);
\draw (0.9,7.7) -- (2.3,9.5);
\draw (5,0) -- (7.3,0.42);
\draw (7.3,0.42) -- (9,2);
\filldraw[fill=black!40,draw=black!80] (0,5) circle (2pt) node[anchor=east] {10};
\filldraw[fill=black!40,draw=black!80] (5,0) circle (2pt) node[anchor=north] {7};
\filldraw[fill=black!40,draw=black!80] (5,10) circle (2pt) node[anchor=south] {1};
\filldraw[fill=black!40,draw=black!80] (10,5) circle (2pt)node[anchor=west] {4};
\filldraw[fill=black!40,draw=black!80] (9,2) circle (2pt) node[anchor=west] {5};
\filldraw[fill=black!40,draw=black!80] (9,8) circle (2pt) node[anchor=west] {3};
\filldraw[fill=black!40,draw=black!80] (1,2) circle (2pt) node[anchor=east] {9};
\filldraw[fill=black!40,draw=black!80] (7.3,0.42) circle (2pt) node[anchor=west] {6};
\filldraw[fill=black!40,draw=black!80] (7.3,9.4) circle (2pt) node[anchor=west] {2};
\filldraw[fill=black!40,draw=black!80] (2.3,9.4) circle (2pt) node[anchor=south] {n};
\filldraw[fill=black!40,draw=black!80] (2.3,0.42) circle (2pt) node[anchor=north] {8};
\filldraw[fill=white!40,draw=white!80] (1.7,7.5) circle (2pt) node[anchor=east] {\dots};
\end{tikzpicture}
\end{document}
它给了我一些类似于我想要的东西,但我只需要图是有向的,但是当我输入类似的东西时:
\draw \[->\](7.3,9.4) -- (5,10);
它总是出错。我尝试安装其他软件包并使用其他编译器(TeXworks、TeXmaker 和 Overleaf),但还是没能解决这个问题。请帮忙。
答案1
这是一个简化事情的建议。
- 循环
\foreach
有助于避免重复。 - 然后使用极坐标。
(120:5)
120
表示角度和5
半径。在循环中,角度为{120-\X*360/12}
,即以360/12=30
度为单位顺时针旋转。 - 标签以相同的角度粘贴,
label={120-\X*360/12}:
确保它们位于“外面”。
人们可以进一步压缩代码,但它可能会变得更加难以理解。
\documentclass[11pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[y=.4cm, x=.4cm,font=\normalsize,>=latex]
\foreach \X [remember=\X as \LastX] in {0,...,10}
{\ifnum\X=0
\node [circle,fill=black!40,label=120:$n$,inner sep=2pt](X\X) at (120:5){};
\else
\node [circle,fill=black!40,label={120-\X*360/12}:$\X$,inner sep=2pt](X\X) at
({120-\X*360/12}:5){};
\draw[black!80,->] (X\LastX) -- (X\X);
\fi}
\node[rotate={30+360/12}] (X11) at ({120+360/12}:5) {$\cdots$};
\draw[black!80,->] (X10) -- (X11);
\draw[black!80,->] (X11) -- (X0);
\end{tikzpicture}
\end{document}