Take the 2-minute tour ×
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

5 Answers 5

up vote 16 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

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

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

I've built on the excellent answer from Alain Matthes above and defined a more direct macro. I've also included an example of its use case.

\newcommand{\tikzAngleOfLine}{\tikz@AngleOfLine}                               
  \def\tikz@AngleOfLine(#1)(#2)#3{%                                            
  \pgfmathanglebetweenpoints{%                                                 
    \pgfpointanchor{#1}{center}}{%                                             
    \pgfpointanchor{#2}{center}}                                               
  \pgfmathsetmacro{#3}{\pgfmathresult}%                                        
  }                                                                            
\newcommand{\tikzMarkAngle}[3]{                                                
\tikzAngleOfLine#1#2{\AngleStart}                                              
\tikzAngleOfLine#1#3{\AngleEnd}                                                
\draw #1+(\AngleStart:0.15cm) arc (\AngleStart:\AngleEnd:0.15cm);              
}                                                                              

\begin{tikzpicture}[scale=4,line width=1pt]                                    
  \coordinate (B) at (0,0);                                                    
  \coordinate (C) at (1,0);                                                    
  \coordinate (A) at (0.5,1.5);                                                
  \draw (A) -- (B) -- (C) -- cycle;                                            
  \node [below left]  at (B) {B};                                              
  \node [below right] at (C) {C};                                              
  \node [above]       at (A) {A};                                              
  \coordinate (D) at (barycentric cs:A=0.5 ,C=0.5);                            
  \node [above right] at (D) {D};                                              
  \draw (B) -- (D);                                                            

  \tikzAngleOfLine(A)(C){\AngleStart}                                          
  \tikzAngleOfLine(A)(B){\AngleEnd}                                            
   \draw (A)+(\AngleStart:0.15cm) arc (\AngleStart:\AngleEnd:0.15cm);          

  \tikzMarkAngle{(C)}{(B)}{(A)}                                                
  \tikzMarkAngle{(D)}{(A)}{(B)}                                                
\end{tikzpicture}   

Here's an example use of the macro.

an example use


I've also included a slightly more involved example below.

another example use

\newcommand{\tikzAngleOfLine}{\tikz@AngleOfLine}
  \def\tikz@AngleOfLine(#1)(#2)#3{%
  \pgfmathanglebetweenpoints{%
    \pgfpointanchor{#1}{center}}{%
    \pgfpointanchor{#2}{center}}
  \pgfmathsetmacro{#3}{\pgfmathresult}%
  }
\newcommand{\tikzMarkAngle}[4][0.15cm]{
\tikzAngleOfLine#2#3{\AngleStart}
\tikzAngleOfLine#2#4{\AngleEnd}
\draw[<->] #2+(\AngleStart:#1) arc (\AngleStart:\AngleEnd:#1);
}

\begin{tikzpicture}[scale=4,line width=1pt]
  \coordinate (B) at (0,0);
  \coordinate (C) at (1,0);
  \coordinate (A) at (0.5,1.5);
  \draw (A) -- (B) -- (C) -- cycle;
  \node [below left]  at (B) {B}; 
  \node [below right] at (C) {C}; 
  \node [above]       at (A) {A};
  \coordinate (D) at (barycentric cs:A=0.5 ,C=0.5);
  \coordinate (E) at (barycentric cs:A=0.40 ,B=0.60);
  \node [above right] at (D) {D};
  \node [above left] at (E) {E};
  \draw (B) -- (D);
  \draw (C) -- (E);
  \draw (E) -- (D);

  \tikzMarkAngle{(A)}{(B)}{(C)}

  \node at ($(A)+(-90:0.23)$) {$20^\circ$};
  \tikzMarkAngle{(B)}{(D)}{(C)}
  \node at ($(B)+(25:0.23)$) {$60^\circ$};
  \tikzMarkAngle{(C)}{(B)}{(E)}
  \node at ($(C)+(155:0.23)$) {$50^\circ$};

  \begin{scope}[color=orange]
  \tikzMarkAngle{(D)}{(E)}{(B)}
  \node at ($(D)+(-20:0.15)$) {?=$30^\circ$};
  \end{scope}

  \tikzMarkAngle{(B)}{(A)}{(D)}
  \node at ($(B)+(55:0.23)$) {$20^\circ$};
  \tikzMarkAngle{(C)}{(E)}{(D)}
  \node at ($(C)+(120:0.23)$) {$30^\circ$};

  \coordinate (F) at (barycentric cs:A=0.50 ,B=0.50);
  \node [above left] at (F) {F};
  \draw (F) -- (D);
  \draw (C) -- (F);

  \coordinate (G) at (intersection of D--B and C--F);
  \node [above] at (G) {G};

 \draw (E) -- (G);
 \begin{scope}[color=blue]
   \tikzMarkAngle{(G)}{(F)}{(E)}
   \node at ($(G)+(145:0.20)$) {$40^\circ$};
   \tikzMarkAngle[0.07cm]{(F)}{(E)}{(G)}
   \node at ($(F)+(-175:0.10)$) {$40^\circ$};
   \tikzMarkAngle{(D)}{(A)}{(F)}
   \node at ($(D)+(135:0.22)$) {$80^\circ$};
 \end{scope}
\end{tikzpicture}
share|improve this answer
    
Welcome to TeX.SX! –  Papiro Jul 13 '13 at 20:59
2  
Thanks @Papiro. I look forward to contributing to the community here. –  gkb0986 Jul 13 '13 at 21:07

Here is a solution using TikZ 3.0:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{quotes,angles}
\begin{document}
\begin{tikzpicture}
  \draw
  (3,-1) coordinate (a) node[right] {a}
  -- (0,0) coordinate (b) node[left] {b}
  -- (2,2) coordinate (c) node[above right] {c}
  pic["$\alpha$",draw=orange,<->,angle eccentricity=1.2,angle radius=1cm] {angle=a--b--c};
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
2  
Sweet! The future's looking pretty bright! –  Jake Oct 8 '13 at 14:23
    
This might not work when the language is set to something other than English. (Didn't work for me in Swedish.) –  Pontus Granström Jul 22 at 11:50
1  
To fix the language/babel problem, put \usetikzlibrary{babel} in the preamble (See tex.stackexchange.com/questions/166772/…). –  Pontus Granström Jul 22 at 11:57
    
Thank you for this answer. Works efficiently... –  Enthusiastic Student Oct 22 at 16:01

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.