14

I am trying to label the two angles in a right triangle and got the following code from this post link. In this code, only the right angle is indicated. Looking at several posts on the subject, I am not able to label the other two angles.

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

\begin{document}
\begin{tikzpicture}[scale=1.25]
\coordinate [label=left:$C$] (A) at (-1.5cm,-1.cm);
\coordinate [label=right:$A$] (C) at (1.5cm,-1.0cm);
\coordinate [label=above:$B$] (B) at (1.5cm,1.0cm);

\draw 
 (A) --
node[above] {$a$} (B) --
node[right] {$c$} (C) -- 
node[below] {$b$} (A);

\draw
(1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);
\tkzMarkAngle[size=1cm,color=cyan,mark=|](C,A,B);% gives error :undefined control sequence
\end{tikzpicture}
\end{document}

Learning from the manual is difficult, unless one already knows quite a lot. I would appreciate if someone can add for me the lines that would label the two sides of this triangle. This will serve me a lot of learning. Greetings of the season.

Thank you all who spent precious time and effort to look at my problem. Having failed to avoid tikz-euclid, I have gone through geogebra and got what I wanted, attached here enter image description here and the code (in case it may be useful to someone esle)

\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{pgf,tikz}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}

\begin{document}
\definecolor{qqwuqq}{rgb}{0.,0.39215686274509803,0.}
\definecolor{uuuuuu}
{rgb}{0.26666666666666666,0.26666666666666666,0.26666666666666666}
\definecolor{qqqqff}{rgb}{0.,0.,1.}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 
45,x=1.0cm,y=1.0cm]
\draw[color=black] (-4.,0.) -- (0.,0.);
draw[color=black] (0.,0.) -- (0.,3.);
\clip(-4.,-0.4) rectangle (0.4,3.4);
\draw [shift={(-4.,0.)},color=qqwuqq,fill=qqwuqq,fill opacity=0.1] (0,0) -- (0.:0.6) arc (0.:36.86989764584402:0.6) -- cycle;
\draw[color=qqwuqq,fill=qqwuqq,fill opacity=0.1] (0.,0.4242640687119284) -- (-0.4242640687119284,0.42426406871192845) -- (-0.4242640687119284,0.) -- (0.,0.) -- cycle; 
\draw (0.,3.)-- (-4.,0.);
\draw (-4.,0.)-- (0.,0.);
\draw (0.,0.)-- (0.,3.);
\draw[color=qqwuqq] (-3.58,0.16) node {$\theta$};
\draw[color=qqwuqq] (0.34,0.33);
\end{tikzpicture}
\end{document}

Thank you very much

Zilore Mumba
  • 1,087
  • 1
    That code does not compile for me. Does it really work for you? Please specify which answer you based your code on. There are many many many! – cfr Jan 01 '17 at 22:43
  • 1
    OK, I see that is the question but it is hidden in a comment in the code. Better to clearly mention the error so people know that's what you want help with! – cfr Jan 01 '17 at 23:02
  • 1
    As your latest edit is essentially an answer to the question as I understand it, I'd suggest posting it as an answer instead, makes it easier for other people who see this post to determine where the question stops and the answers begin. (Answering ones own question is perfectly fine.) – Torbjørn T. Jan 02 '17 at 11:35
  • clicking on "answer your own question" was not giving me anything, that is why I posted an edit. Sorry for the incovenience. – Zilore Mumba Jan 02 '17 at 16:58
  • Have you seen my another answer below? You can vote it, if you prefer. – Sebastiano Jan 02 '17 at 17:16

3 Answers3

16

You are almost there. You just need to add

\usepackage{tkz-euclide}
\usetkzobj{all}

to the preamble.

\documentclass[border=10pt,tikz]{standalone}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}[scale=1.25]
  \coordinate [label=left:$C$] (C) at (-1.5cm,-1.cm);
  \coordinate [label=right:$A$] (A) at (1.5cm,-1.0cm);
  \coordinate [label=above:$B$] (B) at (1.5cm,1.0cm);
  \draw (C) -- node[above] {$a$} (B) -- node[right] {$c$} (A) -- node[below] {$b$} (C);
  \draw (1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);
  \tkzMarkAngle[size=1cm,color=cyan,mark=|](A,C,B)
  \tkzMarkAngle[size=1cm,color=cyan,mark=|](C,B,A)
\end{tikzpicture}
\end{document}

marked angles

EDIT

In a comment you mentioned wanting to avoid tkz-euclide. I actually only used this because the code you posted originally required it. If you wish to mark angles using plain TikZ (insofar as there is such a thing), you might use the angles and quotes libraries, which are part of PGF/TikZ itself.

For example:

\documentclass[border=10pt,tikz]{standalone}
\usetikzlibrary{angles,quotes}
\begin{document}
\begin{tikzpicture}[
  my angle/.style={
    every pic quotes/.append style={text=cyan},
    draw=cyan,
    angle radius=1cm,
  }]
  \coordinate [label=left:$C$] (C) at (-1.5,-1);
  \coordinate [label=right:$A$] (A) at (1.5,-1);
  \coordinate [label=above:$B$] (B) at (1.5,1);
  \draw (C) -- node[above] {$a$} (B) -- node[right] {$c$} (A) -- node[below] {$b$} (C);
  \draw (A) +(-.25,0) |- +(0,.25);
  \pic [my angle, "$\alpha$"] {angle=A--C--B};
  \pic [my angle, "$\beta$"] {angle=C--B--A};
\end{tikzpicture}
\end{document}

without <code>tkz-euclide</code>

cfr
  • 198,882
6

A PSTricks solution using the pst-eucl package:

\documentclass{article}

\usepackage{pst-eucl}
\newcommand*\Label[3]{%
  \pcline[linestyle = none, offset = 6pt](#1)(#2)
  \ncput{#3}}

\begin{document}

\begin{pspicture}(-0.43,-0.35)(5.35,3.4) % boundry found manually
  \pstTriangle[PointSymbol = none](0,0){A}(5,3){B}(5,0){C}
  \pstRightAngle{B}{C}{A}
  \pstMarkAngle[LabelSep = 0.6]{C}{A}{B}{$\alpha$}
  \pstMarkAngle[LabelSep = 0.67]{A}{B}{C}{$\beta$}
  \Label{A}{B}{$c$}
  \Label{B}{C}{$a$}
  \Label{C}{A}{$b$}
\end{pspicture}

\end{document}

output

  • 1
    @cfr, firstly my apologies for not commenting code which did not work and hence my question not being clear. The tikz solution works for me in a standalone document. But this is part of a large document, and in my large document "\usepackage{tkz-euclide}" gives me the error "no \begin{document}". I am using a lot of options in the tikz library, so I do not know where the conflict comes from. I have been avoiding using euclide altogether. The pst-eucl solution by Svend gives "undefined control sequence" on line 11 (pstTriangle[PointSymbol=...). Could it help if I post the whole tikzlibrary? – Zilore Mumba Jan 02 '17 at 04:43
  • 1
    Further comment: removing all "\usepackage{tikz} and \usetikzlibrary" still gives "missing \begin{document}" with "\usepackage{tikz-euclide}" uncommented. – Zilore Mumba Jan 02 '17 at 05:11
  • 1
    @cfr and Sebastiano, I have marked both solutions are correct and useful because they work as standalone on my system but am not able to use the package tikz-euclide, so am looking for a solution which is purely tikz, for my larger document. pstricks does not work at all. – Zilore Mumba Jan 02 '17 at 07:34
  • @ZiloreMumba For PSTricks, you have to compile using either latex --> dvips --> ps2pdf or xelatex. Are you doing that? – Svend Tveskæg Jan 02 '17 at 13:21
  • @ZiloreMumba You cannot ping other people in a conversation they are not part of. So neither Sebastiano or I receive notification that you've left comments addressing us here. You cannot mark more than one answer as correct. You cannot ping more than one person at once. – cfr Jan 02 '17 at 16:47
  • @ZiloreMumba I added tkz-euclide because your existing code required it. You got an error because you weren't loading anything to define the macros you were trying to use. If you get an error when you add the package etc. to your preamble, we need a minimal example which reproduces it and details of the error. You cannot load it in the middle of your document, though. You must put it before \begin{document}. – cfr Jan 02 '17 at 16:49
  • Sorry I was actually trying to thank all the people for spending their time to look at my question. My sincere apologies – Zilore Mumba Jan 02 '17 at 16:56
  • @ZiloreMumba Please see my edited answer above. I've added an answer using TikZ which avoids tkz-euclide and uses the angles and quotes libraries instead. Perhaps that will work better for you. (Certainly, it is easier for me as the manual is in English!) – cfr Jan 02 '17 at 21:44
  • Just to answer an unanswered question @SvendTveskaeg, I do not understand how to use the command latex --> dvips --> ps2pdf. with tikz-euclide, I tried "latex -pdf mylatefile.tex" and "xelatex -pdf mylatexfile.tex". Both of these give "missing \begin{document}" – Zilore Mumba Jan 03 '17 at 20:29
  • Either do (A) latex file.tex and then dvips file.dvi and then ps2pdf file.ps or (B) xelatex file.tex. – Svend Tveskæg Jan 03 '17 at 22:59
4

Now is correct, without errors!

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{tkz-euclide}
\usetkzobj{all}

\usepackage{etoolbox}
\makeatletter

\begin{document}
\begin{tikzpicture}[scale=1.25]
\coordinate [label=left:$C$] (A) at (-1.5cm,-1.cm);
\coordinate [label=right:$A$] (C) at (1.5cm,-1.0cm);
\coordinate [label=above:$B$] (B) at (1.5cm,1.0cm);

\draw 
 (A) --
node[above] {$a$} (B) --
node[right] {$c$} (C) -- 
node[below] {$b$} (A);

\draw
(1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);
\tkzMarkAngle[size=1cm,color=cyan,mark=|](C,A,B);
\end{tikzpicture}
\end{document}

For the second question you can use a grid.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 
45,x=1.0cm,y=1.0cm]
\draw[step=1cm,gray,very thin] (-4,-4) grid (4,4);
\draw[color=black] (-4.,0.) -- (0.,0.);
draw[color=black] (0.,0.) -- (0.,3.);
\clip(-4.,-0.4) rectangle (0.4,3.4);
\draw [shift={(-4.,0.)},color=gray,fill=darkgray,fill opacity=0.1] (0,0) -- (0.:0.6) arc (0.:36.9:0.6) -- cycle;
\draw[color=gray,fill=darkgray,fill opacity=0.1] (0.,0.42) -- (-0.42,0.42) -- (-0.42,0.) -- (0.,0.) -- cycle; 
\draw (0.,3.)-- (-4.,0.);
\draw (-4.,0.)-- (0.,0.);
\draw (0.,0.)-- (0.,3.);
\draw[color=gray] (-3.2,0.4) node {\large $\theta$};
\draw[color=gray] (0.34,0.33);
\end{tikzpicture}
\end{document}

enter image description here

Sebastiano
  • 54,118