我设法找到了下面的图表,但我希望边仅位于连续的外部点之间(即(1,2),(2,3),...,(5,1))
\documentclass[border=3mm,tikz]{standalone}
\begin{document}
\begin{tikzpicture}[
every node/.style={draw,shape=circle,fill=blue,text=white}]
%%%% variable data data
\def\numpoly{8}%number of nodes
\def\startangle{30}%direction of the first node
\def\pradious{33mm}
%------- calculations of the positions angles
\pgfmathparse{int(\startangle+360/\numpoly)}%
\let\nextangle=\pgfmathresult
\pgfmathparse{int(\startangle-360/\numpoly+360)}%
\let\endtangle=\pgfmathresult
%--- nodes
\foreach \i [count=\ii from 1] in {\startangle,\nextangle,...,\endtangle}
\path (\i:\pradious) node (p\ii) {\ii};
%--- interconnections
\foreach \x in {1,...,\numpoly}
\foreach \y in {\x,...,\numpoly}
\draw (p\y) -- (p\x);
\end{tikzpicture}
\end{document}
这是我第一次使用乳胶,所以很抱歉这非常简单而我错过了!
答案1
钛钾Z 已预先定义这些形状。
\documentclass[border=3mm,tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\node[regular polygon,regular polygon sides=8,draw,minimum width=6cm]
(octagon){};
\foreach \X [count=\Y] in {8,...,1}
{\node[draw,shape=circle,fill=blue,text=white] at (octagon.corner \X){\Y}; }
\end{tikzpicture}
\end{document}
附录:只是为了好玩,如果你想任意重新标记角落,这个技巧可能会有所帮助。
\documentclass[border=3mm,tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\node[regular polygon,regular polygon sides=8,draw,minimum width=6cm]
(octagon){};
\foreach \X [evaluate=\X as \Y using {ifthenelse(int(mod(\X+1,8))==0,8,
int(mod(\X+1,8)))}] in {1,...,8}
{\node[draw,shape=circle,fill=blue,text=white] at (octagon.corner \X){\Y}; }
\end{tikzpicture}
\end{document}
您可以\X+1
放置任意内容,例如5-\X
。
或者您也可以使用它rotate
来获得与图片相同的布局:
\documentclass[border=3mm,tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\node[rotate=-30,regular polygon,regular polygon sides=8,draw,minimum width=6cm]
(octagon){};
\foreach \X in {1,...,8}
{\node[draw,shape=circle,fill=blue,text=white] at (octagon.corner \X){\X}; }
\end{tikzpicture}
\end{document}