1

So I'm very new to tikz and I'm trying to create a pattern using a for loop.

\foreach \k in {60,120,180,240,300}
        \filldraw[fill=green!20,draw=anglecolor] (0,0) -- ({\k - 60}:0.35) arc [start angle=\k-60, end angle=\k, radius=0.35];
        \draw (\k - 30:2.2mm) node[anglecolor] {$\theta_r$};
        \draw[very thick, color=tancolor] (0,0) -- (\k:1);

Unfortulately, I get an error saying Missing \endcsname inserted. on the third line. I am using lualatex and I know that all my custom variables (anglecolor, tancolor) are properly defined. How can I fix this error?

2
  • compare ({\k - 60}:0.35) with (\k - 30:2.2mm) should resolve the issue – js bibra Jun 26 '20 at 15:52
  • Unfortunately, that doesn't actually solve the issue... – Kookie Jun 26 '20 at 15:57
4

You should use curly braces {} to wrap the loop body.

\foreach \k in {60,120,180,240,300}
        {\filldraw[fill=green!20,draw=anglecolor] (0,0) -- ({\k - 60}:0.35) arc [start angle=\k-60, end angle=\k, radius=0.35];
        \draw (\k - 30:2.2mm) node[anglecolor] {$\theta_r$};
        \draw[very thick, color=tancolor] (0,0) -- (\k:1);}
1
  • Yep, that worked! It's kinda fascinating how I've read a few guides that don't tell you specifically to wrap loops in curly braces. Thanks! – Kookie Jun 27 '20 at 0:28

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.