1

I want to use the list of fractions flist to label some angles. They will be in the place of the "A".

\begin{tikzpicture}
\edef\r{1}
    \edef\anglist{{30,45,60,120,135,150,210,225,240,300,315,330}}
    %\edef\flist{{\frac{\pi}{6}, \frac{\pi}{4}, \frac{\pi}{3}, \frac{2\pi}{3}, \frac{3\pi}{4}, \frac{5\pi}{6}, \frac{7\pi}{6}, \frac{5\pi}{4}, \frac{4\pi}{3}, \frac{5\pi}{3}, \frac{7\pi}{4}, \frac{11\pi}{6}}}
    \foreach \a in{0,...,11}{
        \pgfmathsetmacro{\tmp}{\flist[\ang]};
        \draw[cycle1] (0,0)--({\r*cos(\anglist[\a])},{\r*sin(\anglist[\a])})node[pos=1.3]{$A$};
}
\end{tikzpicture}

I don't know where is the mistake, but the code above doesn't works.

3
  • 1
    Please don't post code fragments. Instead, put your fragments into a complete compilable document that shows the problem.
    – Alan Munn
    Commented Aug 14, 2017 at 19:55
  • Please make a minimal working example (MWE).
    – dexteritas
    Commented Aug 14, 2017 at 20:04
  • \frac{a}{b} is intended for typesetting a fraction, you seem to want to calculate a/b. pgfmath doesn't understand \frac, but it does understand /, so just use that. Commented Aug 14, 2017 at 20:28

1 Answer 1

4

The tikz \foreach construct supports looping on pairs, precisely to allow what you wish to do.

The output

enter image description here

The code

\documentclass[12pt,tikz]{standalone}
\begin{document}
  % join this
  %30 /\frac{\pi}{6},
  %45 /\frac{\pi}{4},
  %60 /\frac{\pi}{3},
  %120/\frac{2\pi}{3},
  %135/\frac{3\pi}{4},
  %150/\frac{5\pi}{6},
  %210/\frac{7\pi}{6},
  %225/\frac{5\pi}{4},
  %240/\frac{4\pi}{3},
  %300/\frac{5\pi}{3},
  %315/\frac{7\pi}{4},
  %330/\frac{11\pi}{6},
\begin{tikzpicture}[scale=2]
    \def\r{1}
    \foreach \cAngle/\dAngle in {30/\frac{\pi}{6},45/\frac{\pi}{4},60/\frac{\pi}{3},120/\frac{2\pi}{3},135/\frac{3\pi}{4},150/\frac{5\pi}{6},210/\frac{7\pi}{6},225/\frac{5\pi}{4},240/\frac{4\pi}{3},300/\frac{5\pi}{3},315/\frac{7\pi}{4},330/\frac{11\pi}{6}}
    {
        \draw (0,0)--({\r*cos(\cAngle)},{\r*sin(\cAngle)}) node[pos=1.3]{$\dAngle$};
    }
\end{tikzpicture}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .