![绘制多边形](https://linux22.com/image/386017/%E7%BB%98%E5%88%B6%E5%A4%9A%E8%BE%B9%E5%BD%A2.png)
如何使用蒂克兹包来实现以下。我看了在但还是没能完成。任何帮助我都非常感谢。
答案1
有很多种可能的方法来绘制它,这是其中之一。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix,backgrounds}
\begin{document}
\begin{tikzpicture}
\matrix[matrix of nodes,nodes={circle,draw,fill=white},column sep=3mm,row sep=3mm] (mat) { 2 & 7 & 6 \\
9 & 5 & 1\\
4 & 3 & 8\\
};
\foreach \X in {1,2,3}
{\foreach \Y [evaluate=\Y as \Z using {int(10*\X+\Y)}]in {1,2,3}
{\ifnum\Z=22
\else
\draw (mat-\X-\Y) -- (mat-2-2);
\fi}}
\begin{scope}[on background layer]
\draw (mat-3-1) rectangle (mat-1-3);
\end{scope}
\end{tikzpicture}
\end{document}
或者,如果你不想填充节点,你可以使用
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix[matrix of nodes,nodes={circle,draw},column sep=3mm,row sep=3mm] (mat) { 2 & 7 & 6 \\
9 & 5 & 1\\
4 & 3 & 8\\
};
\foreach \X [count=\XX starting from 0] in {1,2,3}
{\foreach \Y [evaluate=\Y as \Z using {int(10*\X+\Y)},count=\YY starting from 0]in {1,2,3}
{\ifnum\Z=22
\else
\draw (mat-\X-\Y) -- (mat-2-2);
\fi
\ifnum\X=1
\else
\draw (mat-\XX-\Y) -- (mat-\X-\Y);
\fi
\ifnum\Y=1
\else
\draw (mat-\X-\YY) -- (mat-\X-\Y);
\fi
}}
\end{tikzpicture}
\end{document}