I would like to draw a pentagon. This works

\draw \foreach \alpha in {0,72,...,359} {
    \ifdim\alpha pt=0pt \else--\fi
} -- cycle;

while this

\draw \foreach \alpha in {0,72,...,359} {
    (270+\alpha:1) --
} cycle;

gives the error Cannot parse this coordinate.

Can someone explain why?

  • 3
    See this one tex.stackexchange.com/a/132162/3235 – percusse Jan 14 '15 at 21:30
  • Very stupid interface from the part of LaTeX/TikZ! But thanks a lot for the explanation, this will save my computer a few occasions of being shouted at. – gTcV Jan 15 '15 at 7:44
  • Why stupid? For example the proper way is \draw (270:1) \foreach\x in{1,...,4}{--(270+\x*72:1)}--cycle;. – percusse Jan 15 '15 at 13:44
  • Because I have to give special treatment to the first step. Not much of an issue in this simple example, but very nasty once it gets more complicated. – gTcV Jan 15 '15 at 14:38
  • Open another question or edit this one to include the nasty case. Then you can ask for others' opinion for simplifications. People tend to love TikZ code golfing. – percusse Jan 15 '15 at 14:40

You can define the path before to use it:


  \foreach \alpha in {0,72,...,359}{
    \xdef\p{\p (270+\alpha:1) --}
    \draw \p cycle;

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.