Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am able to draw a nice right triangle with

\begin{tikzpicture}[thick]
  \draw (0,0)  -- (4,0) node[midway,below]{$f$} -- (4,2) node[midway,right]{$\frac{x}{2}$}-- cycle;
\end{tikzpicture}

Now I want to label the left angle of the triangle and I am stuck on how to do this.

share|improve this question
1  
The question is "how to label a vertice" and it's more complicated to label an angle ! – Alain Matthes Jun 15 '11 at 13:56
@Altermundus: So something like tpub.com/math1/20.htm57.gif, especially the arrows that point to the start/end of the angle, is not easy doable? – Flow Jun 15 '11 at 16:28
Yes it's possible but not with the same facility ! :) – Alain Matthes Jun 15 '11 at 16:34
@Altermundus: Could you maybe elaborate this a bite more? I am new to tikz. – Flow Jun 15 '11 at 16:56
@Flow Without the arrows, it's simple. You can clip the triangle and draw a circle with center A. If you know the angle, it's also simple, you can draw an arc (look at my question tex.stackexchange.com/questions/20833/…) but If you don't know the value of the angle, you need to calculate this value and then you need to draw the arc. – Alain Matthes Jun 15 '11 at 18:20

3 Answers

up vote 10 down vote accepted

My answer shows how to label the vertex and the angle. The macro tikzAngleOfLineis not optimized

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\newcommand{\tikzAngleOfLine}{\tikz@AngleOfLine}
  \def\tikz@AngleOfLine(#1)(#2)#3{%
  \pgfmathanglebetweenpoints{%
    \pgfpointanchor{#1}{center}}{%
    \pgfpointanchor{#2}{center}}
  \pgfmathsetmacro{#3}{\pgfmathresult}%
  }

  \begin{tikzpicture}
    \coordinate (A) at (1,1);
    \coordinate (B) at ($(A)+(25:3)$);
    \coordinate (C) at ($(A)+(100:5)$);
    \draw (A) node[left]{$A$} -- (B) node[right]{$B$}node[midway,below]{$c$} -- (C)node[above]{$C$}node[midway,above]{$a$} -- (A)node[midway,left]{$b$};

    \tikzAngleOfLine(A)(B){\AngleStart}
    \tikzAngleOfLine(A)(C){\AngleEnd}
    \draw[red,<->] (A)+(\AngleStart:2cm) arc (\AngleStart:\AngleEnd:2 cm);
    \node[circle,fill=green] at ($(A)+({(\AngleStart+\AngleEnd)/2}:1 cm)$) {$\alpha$};
\end{tikzpicture}
\end{document} 

enter image description here

share|improve this answer

I have searched for many solutions. Finally, no one is satisfactory.

Solution 1: as shown in here, use

\tkzMarkAngle and \tkzLabelAngle

Problem: can't draw an arrow on the arc.

Solution 2: as show in the same place, use

\begin{scope}
  \path[clip] (A) -- (E) -- (F) -- cycle;
  \draw [red, fill=red!20] (A) circle (10pt);
\end{scope}

Problem: can't draw an arrow on the arc.

Solution 3: the solution in the accepted answer might be complicated for a beginner. And I tried the code, it seems the direction of the arc is not what I expected.

==================================================

My solution: Of course there are many other good solutions. Regarding the problem I am interested in, I came up with a simple solution. I believe many people already know about this. Just post it here for a memo.

%Requires \usetikzlibrary{calc} in the preamble
\begin{tikzpicture}
    \coordinate (B) at (2.345,-1.234);
    \coordinate (A) at (0,0);
    \coordinate (C) at (-2.1,3.2);
    \draw [densely dotted, thick] (B)--(A)--(C);
    \draw (A) node[below] {$A$};
    \draw (B) node[below] {$B$};
    \draw (C) node[below left] {$C$};
    % label the angle subtended at p1 by p2 and p3
    \def\angleRadius{30pt}
    % draw the arc
    \draw[red,->,thick] let \p1=(A), \p2=(B), \p3=(C), 
        \n1={atan2(\x2-\x1,\y2-\y1)}, \n2={atan2(\x3-\x1,\y3-\y1)} in
        ($(\p1)!\angleRadius!(\p2)$) arc (\n1:\n2:\angleRadius);
    % draw the label
    \draw[red] let \p1=(A), \p2=(B), \p3=(C), 
         \n1={atan2(\x2-\x1,\y2-\y1)}, \n2={atan2(\x3-\x1,\y3-\y1)} in
         (\p1)+(\n1/2+\n2/2:\angleRadius) node[above] {$\alpha$};
\end{tikzpicture}

Result:

enter image description here

We can use the following code to label the angle which is larger than 180.

\def\angleRadius{30pt}
\draw[red,->,thick] let \p1=(A), \p2=(B), \p3=(C), \n1={atan2(\x2-\x1,\y2-\y1)}, \n2={atan2(\x3-\x1,\y3-\y1)} in
    ($(\p1)!\angleRadius!(\p2)$) arc (\n1:\n2-360:\angleRadius);
\draw[red] let \p1=(A), \p2=(B), \p3=(C), \n1={atan2(\x2-\x1,\y2-\y1)}, \n2={atan2(\x3-\x1,\y3-\y1)} in
    (\p1)+(\n1/2+\n2/2+180:\angleRadius) node[below] {$\alpha$};

The result is:

enter image description here

Features of the solution:

  1. Simple. Simply input the three points that determine the angle.
  2. the arc is generated by arc command. Can set the arrow of the arc and of course other properties.
  3. Require \usetikzlibrary{calc}, but no \usepackage{tkz-euclide}.
share|improve this answer
You are missing the angle label. Also the problems that you have given are also solvable but still this is also nice. – percusse Oct 5 '12 at 16:22
@percusse: I have added the label. (I don't know how to integrate the label and arc under one \draw command.) BTW, thanks for editing my answer. Based on your version, I revised it a little bit. I still prefer to introduce \p1,\p2,\p3 instead of only \p1 and \p2 because if I have other three points, I can simply put them in the p1,p2,p3 places, and need not to modify any other things. – Shiyu Oct 6 '12 at 3:35

You can insert a node at the start of the triangle, at (0,0), and put a label to the left of it with node[left]{$A$}. A full example:

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[thick]
  \draw (0,0) node[left]{$A$}  -- (4,0) node[midway,below]{$f$} -- (4,2) node[midway,right]{$\frac{x}{2}$}-- cycle;
\end{tikzpicture}

\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.