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.

The sample code:

\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw  ( 0 , 0 ) coordinate (A) 
    -- ( 4 , 0 ) coordinate (C) 
    -- ( 0 , 3 ) coordinate (B) 
    -- (0,    0);
\end{tikzpicture}
\end{document}

The figure:

Right Triangle

I would like to use a box in the lower left angle of the triangle to indicate a right angle.

share|improve this question
1  
Hi Stuart, welcome to the site! There's been a similar question before: Insertion of perpendicular symbol at intersection of two perpendicular lines –  Jake Jan 16 at 8:57
    
Excellent, very helpful link. Exactly what I was looking for. –  StuartRCarter Jan 16 at 9:16
add comment

5 Answers

For this simple case, you can just draw a square at (A):

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
\draw  ( 0 , 0 ) coordinate (A)
    -- ( 4 , 0 ) coordinate (C)
    -- ( 0 , 3 ) coordinate (B)
    -- (0,  0);
\draw [fill=red](A) rectangle ++(0.5,0.5) node[above right]{$90^\circ$};
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
1  
To make it a little more general you could use relative coordinates, i.e. \draw [fill=red](A) rectangle ++(0.5,0.5). –  Torbjørn T. Jan 16 at 12:59
    
@TorbjørnT. Good point, Thanks and edited. :) –  Harish Kumar Jan 16 at 13:03
add comment

With the help of the new library angles of TikZ 3.0.0 and a small patch, it is possible to get:

enter image description here

thanks to:

\begin{tikzpicture}
\draw  ( 0 , 0 ) coordinate (A) 
    -- ( 4 , 0 ) coordinate (C) 
    -- ( 0 , 3 ) coordinate (B) 
    -- ( 0 , 0 )
    pic [draw,blue,thick,angle radius=0.5cm]  {squared angle = A--C--B}
    pic [draw,red,thick,angle radius=0.5cm]   {squared angle = C--A--B}
    pic [draw,green,thick,angle radius=0.5cm] {squared angle = C--B--A};
    ;
\end{tikzpicture}

The complete code:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles}

\makeatletter
\tikzset{
  pics/squared angle/.style = {
    setup code  = \tikz@lib@angle@parse#1\pgf@stop,
    background code = \tikz@lib@angle@background#1\pgf@stop,
    foreground code = \tikz@lib@squaredangle@foreground#1\pgf@stop,  
  },
  pics/squared angle/.default=A--B--C,
  angle eccentricity/.initial=.6,
  angle radius/.initial=5mm
}

\def\tikz@lib@squaredangle@foreground#1--#2--#3\pgf@stop{%
  \path [name prefix ..] [pic actions]
  ([shift={(\tikz@start@angle@temp:\tikz@lib@angle@rad pt)}]#2.center)
    |-
  ([shift={(\tikz@end@angle@temp:\tikz@lib@angle@rad pt)}]#2.center);
  \ifx\tikzpictext\relax\else%
    \def\pgf@temp{\node()[name prefix
      ..,at={([shift={({.5*\tikz@start@angle@temp+.5*\tikz@end@angle@temp}:\pgfkeysvalueof{/tikz/angle
            eccentricity}*\tikz@lib@angle@rad pt)}]#2.center)}]}
    \expandafter\pgf@temp\expandafter[\tikzpictextoptions]{\tikzpictext};%
  \fi
}
\makeatother

\begin{document}
\begin{tikzpicture}
\draw  ( 0 , 0 ) coordinate (A) 
    -- ( 4 , 0 ) coordinate (C) 
    -- ( 0 , 3 ) coordinate (B) 
    -- ( 0 , 0 )
    pic [draw,blue,thick,angle radius=0.5cm]  {squared angle = A--C--B}
    pic [draw,red,thick,angle radius=0.5cm]   {squared angle = C--A--B}
    pic [draw,green,thick,angle radius=0.5cm] {squared angle = C--B--A};
    ;
\end{tikzpicture}
\end{document}

The desired output seems to have the box filled in red as well as a label, hence let's use the quotes library:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}

\makeatletter
\tikzset{
  pics/squared angle/.style = {
    setup code  = \tikz@lib@angle@parse#1\pgf@stop,
    background code = \tikz@lib@angle@background#1\pgf@stop,
    foreground code = \tikz@lib@squaredangle@foreground#1\pgf@stop,  
  },
  pics/squared angle/.default=A--B--C,
  angle eccentricity/.initial=.6,
  angle radius/.initial=5mm
}

\def\tikz@lib@squaredangle@foreground#1--#2--#3\pgf@stop{%
  \path [name prefix ..] [pic actions]
  ([shift={(\tikz@start@angle@temp:\tikz@lib@angle@rad pt)}]#2.center)
    |-
  ([shift={(\tikz@end@angle@temp:\tikz@lib@angle@rad pt)}]#2.center);
  \ifx\tikzpictext\relax\else%
    \def\pgf@temp{\node()[name prefix
      ..,at={([shift={({.5*\tikz@start@angle@temp+.5*\tikz@end@angle@temp}:\pgfkeysvalueof{/tikz/angle
            eccentricity}*\tikz@lib@angle@rad pt)}]#2.center)}]}
    \expandafter\pgf@temp\expandafter[\tikzpictextoptions]{\tikzpictext};%
  \fi
}
\makeatother

\begin{document}
\begin{tikzpicture}
\draw  ( 0 , 0 ) coordinate (A) 
    -- ( 4 , 0 ) coordinate (C) 
    -- ( 0 , 3 ) coordinate (B) 
    -- ( 0 , 0 )
    pic [draw,fill=red,angle radius=0.5cm,angle eccentricity=2,
    "$90^\circ$" {black,font=\footnotesize}]   {squared angle = C--A--B}
    ;
\end{tikzpicture}
\end{document}

The result:

enter image description here

share|improve this answer
2  
"Small patch" is the understatement of the day. –  Thorsten Donig Jan 16 at 9:32
1  
@ThorstenDonig: a suggestion: make a diff of the original library; the change concerns only two lines of code. –  Claudio Fiandrino Jan 16 at 9:35
    
Can this be made to work when the sides are not axis-aligned? –  Neil G Feb 10 at 4:45
    
@NeilG: of course it should be possible, but very complex. Basically, you have to change the |- in ([shift={(\tikz@start@angle@temp:\tikz@lib@angle@rad pt)}]#2.center) |- so that the first part of the path would be orthogonal to the base line of the triangle. –  Claudio Fiandrino Feb 10 at 7:34
    
ok thank you... –  Neil G Feb 10 at 7:41
add comment

This is an approach simplified by »tkz-euclide«, which is mentioned indirectly in the comment to your question. Wherever the points are located that define the triangle, the right angle will be marked automatically.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{tkz-euclide}
\usetkzobj{all}

\begin{document}
  \begin{tikzpicture}
    \tkzDefPoint(0,0){A}
    \tkzDefPoint(0,3){B}
    \tkzDefPoint(4,0){C}
    \tkzMarkRightAngle[draw=red,fill=red](B,A,C)
    \tkzDrawPolygon(A,B,C)
  \end{tikzpicture}
\end{document}

For details please refer to the package manual, which is unfortunately only available in French.


enter image description here

share|improve this answer
add comment

This is how. Take the (A) as your reference point. Then (1) yshift to move the starting point up a little; (2) xshift to determine the end point; (3) connect these two points using -| (going horizontally and then vertically to the end point.) enter image description here

\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw  ( 0 , 0 ) coordinate (A) 
    -- ( 4 , 0 ) coordinate (C) 
    -- ( 0 , 3 ) coordinate (B) 
    -- (0,  0);
%\draw [red]([yshift=0.5cm]A) -| node[above right]{$90^\circ$}; % generates red line
\draw [fill=red]([yshift=0.5cm]A) -| node[above right]{$90^\circ$} ([xshift=0.5cm]A) 
-- (A) -- cycle ;   % if path is used, the square becomes invisible.
\end{tikzpicture}
\end{document}
share|improve this answer
    
How could one label the vertices, please? (Say by a letter X) –  Abhimanyu Arora Jan 16 at 9:03
    
Is there a way to use a simple command, rather than drawing it? In my more complicated figures the triangles are rotated and drawing is a hassle, especially if I want to go back and change anything. –  StuartRCarter Jan 16 at 9:03
1  
@AbhimanyuArora -- Use node technique as shown here\draw ([yshift=0.5cm]A) -| node[above right]{$90^\circ$} ([xshift=0.5cm]A){}; Same idea applies to the triangle tips. –  Jesse Jan 16 at 9:07
    
@StuartRCarter -- Please refer to Jake's comment and take a look, to see if his 3-point command is what you need. –  Jesse Jan 16 at 9:16
add comment

With PSTricks.

\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}(6,6)
    \pstGeonode[CurveType=polygon,PosAngle={-90,0,90}](1,1){A}(5,1){B}(1,5){C}
    \pstRightAngle[fillstyle=solid,fillcolor=red]{B}{A}{C}
\end{pspicture}
\end{document}

enter image description here

share|improve this answer
add comment

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.