I'm trying to draw a triangle using TikZ. I managed to get it completed, but now I'm having trouble with getting the node to go into the body of the triangle. I've only been using TikZ for a couple of days so this basic exercise has taken much longer than I care to admit.
How would I put the node within the body?
Although this does in fact draw a triangle, would you consider it properly done? Is there a better way?
\begin{center}
\begin{tikzpicture}
\draw[gray] ++(150:2.3) -- (0,0); %hypotenuse
\draw[teal] ++(180:2) -- (0,0); %adjacent
\draw[orange] (-2,1.15) -- (-2,0); %opposite
\draw[thin] (-0.5,0.25) arc (150:180:0.5)
node[left] {\small $30^\circ$};
\end{tikzpicture}
\end{center}
Best Answer
Processing the original code:
and zooming the resulting object, reveals two additional problems: the arc doesn't touch the hypotenuse and the hypotenuse and the shorter cathetus don't intersect:
Both problems are due basically to the same reason: manual calculation of coordinates.
To solve the problem with the arc, I would suggest you to use clipping and an additional node to draw the circle; in this way, you solve two problems: the arc is correctly drawn in an automated way (no need to guess angles as in the other answers) and you gain finer control over the label position:
There's still one other detail to improve: the hypotenuse and the opposite cathetus not intersecting. This can be solved by using the
intersections
library to automatically do the calculation of the intersection between the prolongations of the opposite cathetus and the hypotenuse: