我想画这个图:正五边形的每一边都被五个圆点代替。
\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{calc}
\newcommand{\drawLineWithPoints}[2]{
\foreach \i in {0,0.25,0.5,0.75,1} {
\coordinate (point) at ($#1!\i!#2$);
\draw (point) circle (2pt);
}
}
\begin{document}
\begin{tikzpicture}
\node[minimum size=4cm, regular polygon, regular polygon sides=5] (a) {};
\foreach \i in {1,...,5}{
\pgfmathtruncatemacro{\j}{\i+1}
\ifnum\j>5
\pgfmathtruncatemacro{\j}{1}
\fi
\drawLineWithPoints{(a.corner \i)}{(a.corner \j)}
}
\end{tikzpicture}
\end{document}
但它向我显示了! Package PGF Math Error: Unknown function
角落'(在'角落 0')。'
如果我放弃 for 循环并\drawLineWithPoints
逐一编写每个语句,它就可以正常工作。
\begin{tikzpicture}
\node[minimum size=4cm, regular polygon, regular polygon sides=5] (a) {};
\drawLineWithPoints{(a.corner 1)}{(a.corner 2)}
\drawLineWithPoints{(a.corner 2)}{(a.corner 3)}
\drawLineWithPoints{(a.corner 3)}{(a.corner 4)}
\drawLineWithPoints{(a.corner 4)}{(a.corner 5)}
\drawLineWithPoints{(a.corner 5)}{(a.corner 1)}
\end{tikzpicture}
为什么?