![foreach 之后的坐标](https://linux22.com/image/303818/foreach%20%E4%B9%8B%E5%90%8E%E7%9A%84%E5%9D%90%E6%A0%87.png)
我想画一个五边形。这个可以
\draw \foreach \alpha in {0,72,...,359} {
\ifdim\alpha pt=0pt \else--\fi
(270+\alpha:1)
} -- cycle;
虽然这
\draw \foreach \alpha in {0,72,...,359} {
(270+\alpha:1) --
} cycle;
给出错误Cannot parse this coordinate.
有人能解释一下为什么吗?
答案1
您可以在使用它之前定义路径:
\documentclass[varwidth,border=7mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\xdef\p{}
\foreach \alpha in {0,72,...,359}{
\xdef\p{\p (270+\alpha:1) --}
}
\begin{tikzpicture}
\draw \p cycle;
\end{tikzpicture}
\end{document}