22

I'm using LaTeX with TikZ to create a (right-angle) triangle. Now I would like to label each angle by adding a half circle and a text label.

Unfortunately I only managed to create a label for the gamma angle. What do I need to do in order to put such a label into the remaining corners?

\begin{tikzpicture}[thick]
\draw(0,0) -- (90:2cm) node[midway,left]{$opposite leg$} -- (0:4cm) node[midway,above right]{$hypotenuse$} -- (0,0) node[midway,below]{$adjacent leg$};
\draw[fill=lightgray, thick] (0,0) -- (0:0.8cm) arc (0:90:0.8cm) node at (45:0.5cm) {$\gamma$} -- cycle;
\end{tikzpicture}
30

I'd use tkz-euclide for this task. It provides a nice macro \tkzMarkAngle which is really of help in this case.

The code:

\documentclass[tikz,border=2pt,png]{standalone}
\usepackage{tkz-euclide}
\usetkzobj{all}

\begin{document}
\begin{tikzpicture}[thick]
\coordinate (O) at (0,0);
\coordinate (A) at (4,0);
\coordinate (B) at (0,2);
\draw (O)--(A)--(B)--cycle;

\tkzLabelSegment[below=2pt](O,A){\textit{adjacent leg}}
\tkzLabelSegment[left=2pt](O,B){\textit{opposite leg}}
\tkzLabelSegment[above right=2pt](A,B){\textit{hypotenuse}}

\tkzMarkAngle[fill= orange,size=0.65cm,%
opacity=.4](A,O,B)
\tkzLabelAngle[pos = 0.35](A,O,B){$\gamma$}

\tkzMarkAngle[fill= orange,size=0.8cm,%
opacity=.4](B,A,O)
\tkzLabelAngle[pos = 0.6](B,A,O){$\alpha$}

\tkzMarkAngle[fill= orange,size=0.7cm,%
opacity=.4](O,B,A)
\tkzLabelAngle[pos = 0.5](O,B,A){$\beta$}


\end{tikzpicture}
\end{document}

The result:

enter image description here

Disclaimer

Hoping that the labels are right.

As Torbjørn T. was suggesting in its comment, it is even possible to create square angles thanks to the macro \tkzMarkRightAngle. The previous example becomes:

\documentclass[tikz,border=2pt,png]{standalone}
\usepackage{tkz-euclide}
\usetkzobj{all}

\begin{document}
\begin{tikzpicture}[thick]
\coordinate (O) at (0,0);
\coordinate (A) at (4,0);
\coordinate (B) at (0,2);
\draw (O)--(A)--(B)--cycle;

\tkzLabelSegment[below=2pt](O,A){\textit{adjacent leg}}
\tkzLabelSegment[left=2pt](O,B){\textit{opposite leg}}
\tkzLabelSegment[above right=2pt](A,B){\textit{hypotenuse}}

\tkzMarkRightAngle[fill=orange,size=0.5,opacity=.4](A,O,B)% square angle here
\tkzLabelAngle[pos = 0.35](A,O,B){$\gamma$}

\tkzMarkAngle[fill= orange,size=0.8cm,%
opacity=.4](B,A,O)
\tkzLabelAngle[pos = 0.6](B,A,O){$\alpha$}

\tkzMarkAngle[fill= orange,size=0.7cm,%
opacity=.4](O,B,A)
\tkzLabelAngle[pos = 0.5](O,B,A){$\beta$}

\end{tikzpicture}
\end{document}

The result:

enter image description here

  • That's an awesome solution. (And yes, the labels are right. ;-)) – Patrick Feb 2 '13 at 13:57
  • @T.Verron: that's the first thing done after having drawn the triangle :) – Claudio Fiandrino Feb 3 '13 at 8:53
  • I know the OP specified an arc also for the right angle \gamma, but I'll just mention that if one wants a square instead, then one can use \tkzMarkRightAngle[fill=orange,size=0.5,opacity=.4](A,O,B). – Torbjørn T. Aug 24 '13 at 18:19
  • @TorbjørnT.: it might be a nice addition, thanks. I'll edit as soon as possible. – Claudio Fiandrino Aug 25 '13 at 10:20
8

A solution with 'pure' tikz could be:

\documentclass[tikz]{standalone}

\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}[thick]
\draw(0,0) -- (90:2cm) node[midway,left]{$opposite\ leg$} -- (0:4cm) node[midway,above right]{$hypotenuse$} -- (0,0) node[midway,below]{$adjacent\ leg$};
\draw[fill=lightgray, thick] (0,0) -- (0:0.8cm) arc (0:90:0.8cm) node at (45:0.5cm) {$\gamma$} -- cycle;
\draw[fill=lightgray, thick] (4,0) -- ++(180:0.8cm) arc (180:180-atan2(4,2):0.8cm) node at ($(167:0.6cm)+(4,0)$) {$\alpha$} -- cycle;
\draw[fill=lightgray, thick] (0,2) -- ++(-90:0.8cm) arc (-90:-90+atan2(2,4):0.8cm) node at ($(-60:0.5cm)+(0,2)$) {$\beta$} -- cycle;
\end{tikzpicture}
\end{document}

Note that you need the calc library and you need to tweak the coordinates by hand if you change the size of the triangle. Of course you can parametrize to some extent by defining lengths (e.g. \def\adjleg{4} and \def\oppleg{2}) and use these in the figure. The angles are a bit more difficult, though.

enter image description here

  • This does not seem to work for me. I get this image instead using TeXLive2013. – Peter Grill Jun 8 '14 at 5:47
  • There was a change in the atan2 function from v2.x to v3 of pgf. The order of the arguments was swapped from atan2(x,y) to (the more common) atan2(y,x). So the first should now be atan2(2,4), and the second atan2(4,2), not the other way around. – Torbjørn T. May 7 '18 at 10:51

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.