1

I'm trying to draw the arc of an angle between two lines in tikz. I'm using the angles library and have pretty much copied the example from the manual, but when I try to label the arc, I get the following error:

! Missing \endcsname inserted.
<to be read again>
                   \theta
l.29 ...c [draw, "$\theta$", angle eccentricity=3]{angle=P--V--Q};

I am following the syntax from this answer. But I have the same trouble using the syntax from the manual pg 570.

Removing the label allows me to draw the arc no trouble. But I would really like to put a theta in my diagram. I thought it might be an escaping issue so I tried labelling with "$t$", and then "t". In the last case the error tells me tikz doesn't know of the label t.

enter image description here

my drawing code is below

\documentclass[border=20pt]{standalone}

\usepackage{tikz} \usetikzlibrary{calc,angles}

\begin{document}

\begin{tikzpicture}

  \def \radius{3.5}
  \coordinate (V) at ($(0,0)!\radius cm!rand*45:(0,\radius)$);

  \path (-\radius, 0) coordinate(P) -- 
               coordinate[midway](O)
               (\radius, 0) coordinate(Q);

  % Draw semicircle
  \draw (Q) arc(0:180:\radius1);
  \draw[shorten &lt;=-5mm, shorten &gt;=-5mm] (P) -- (Q);

  %draw an arc starting at [partway from V to Q], to[ partway from V to P]
  \draw [color=blue] (P)--(V)--(Q);
  \pic [draw, &quot;$\theta$&quot;, angle eccentricity=3] {angle=P--V--Q};


  \node at (O) [below]  {$O$};
  \node at (P) [below]  {$P$};
  \node at (Q) [below]  {$Q$};
  \node at (V) [above]  {$V$};

  \foreach \p in {O,P,Q, V}{
    \fill (\p) circle (1pt);
  }\

\end{tikzpicture}

\end{document}

2 Answers2

2

Your problem is solved by @Roland comment, so here are some off-topic suggestions:

\documentclass[border=20pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,
                calc,
                quotes} % <---

\begin{document} \begin{tikzpicture} \def \radius{3.5} \coordinate (V) at ($(0,0)!\radius cm!rand*45:(0,\radius)$); \path (-\radius, 0) coordinate[label=below:$P$] (P) % <--- -- coordinate[label=below:$O$] (O) (\radius, 0) % <--- coordinate[label=below:$Q$] (Q); % <--- % draw semicircle \draw (Q) arc(0:180:\radius); \draw[shorten <=-5mm, shorten >=-5mm] (P) -- (Q); % draw triangles's cathetus \draw [color=blue, semithick] (P)--(V)--(Q); % draw angle \pic [draw=blue, text=red, "$\theta$", angle eccentricity=1.5] {angle=P--V--Q}; % <--- % dots
\foreach \p in {O,P,Q, V}{\fill (\p) circle[radius=1.5pt];} \end{tikzpicture} \end{document}

Edit: colored angle as you desired in your comment.

enter image description here

Zarko
  • 296,517
  • Thanks for the clean up suggestions. As an aside how would I make the label theta a different color to the arc (say blue and red respectivley)? Should I open a seperate question for that – Andrew Micallef Feb 16 '21 at 00:56
  • nvm pic ["${\color{red}\theta}$", draw=blue, angle eccentricity=1.5] {angle=P--V--Q} – Andrew Micallef Feb 16 '21 at 00:59
0

Even if the previous answer is such a clean solution, I think you would definitely discover the tkz-euclide package which is extremely versatile when it comes to drawing mathematical geometric figures. I didn't rewrite all your figure with tkz-euclid commands, but you could save time by doing it for your future projects. Here, the only change is for drawing and labeling the angle.

\documentclass[border=20pt]{standalone}

\usepackage{tikz} \usetikzlibrary{calc,angles} \usepackage{tkz-euclide}

\begin{document}

\begin{tikzpicture}

  \def \radius{3.5}
  \coordinate (V) at ($(0,0)!\radius cm!rand*45:(0,\radius)$);

  \path (-\radius, 0) coordinate(P) -- 
               coordinate[midway](O)
               (\radius, 0) coordinate(Q);

  % Draw semicircle
  \draw (Q) arc(0:180:\radius1);
  \draw[shorten &lt;=-5mm, shorten &gt;=-5mm] (P) -- (Q);

  %draw an arc starting at [partway from V to Q], to[ partway from V to P]
  \draw [color=blue] (P)--(V)--(Q);

  %-------------- Here's the use of tkz-euclide-----
  \tkzMarkAngle[color=blue,mark=none,size=.5](P,V,Q)
  \tkzLabelAngle[color=red,pos=0.8](P,V,Q){$\theta$}
  %-------------------------------------------------


  \node at (O) [below]  {$O$};
  \node at (P) [below]  {$P$};
  \node at (Q) [below]  {$Q$};
  \node at (V) [above]  {$V$};

  \foreach \p in {O,P,Q, V}{
    \fill (\p) circle (1pt);
  }\

\end{tikzpicture}

\end{document}

tkzMarkAngle

SebGlav
  • 19,186
  • 1
    ah, thanks for that. I poked my nose into tikz-euclid after you suggested it the other day, but immediatly ran into trouble in a foreach loop which I found I could resolve by not using euclid. Perhaps you might care to take a look at that question? – Andrew Micallef Feb 16 '21 at 22:58