# How do I draw a little red square to label my right triangle?

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:

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

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

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,
}

\def\tikz@lib@squaredangle@foreground#1--#2--#3\pgf@stop{%
\path [name prefix ..] [pic actions]
|-
\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
\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,
}

\def\tikz@lib@squaredangle@foreground#1--#2--#3\pgf@stop{%
\path [name prefix ..] [pic actions]
|-
\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
\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 )
"$90^\circ$" {black,font=\footnotesize}]   {squared angle = C--A--B}
;
\end{tikzpicture}
\end{document}


The result:

• "Small patch" is the understatement of the day. Jan 16 '14 at 9:32
• @ThorstenDonig: a suggestion: make a diff of the original library; the change concerns only two lines of code. Jan 16 '14 at 9:35
• Can this be made to work when the sides are not axis-aligned? Feb 10 '14 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. Feb 10 '14 at 7:34
• Have you considered to submit your code to be included in angles library? May 6 '14 at 7:00

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}


• To make it a little more general you could use relative coordinates, i.e. \draw [fill=red](A) rectangle ++(0.5,0.5). Jan 16 '14 at 12:59
• @TorbjørnT. Good point, Thanks and edited. :)
– user11232
Jan 16 '14 at 13:03

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.

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.)

\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}

• How could one label the vertices, please? (Say by a letter X) Jan 16 '14 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. Jan 16 '14 at 9:03
• @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. Jan 16 '14 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. Jan 16 '14 at 9:16

Note : Since version 3.1 of TikZ right angle is part of the standard angles library. It works in the same way as angle pic.

This answer is very close to the answer of @ClaudioFiandrino, which is a slight modification of the standard angles library.

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

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

\def\tikz@lib@rightangle@background#1--#2--#3\pgf@stop{%
\path [name prefix ..] [pic actions, draw=none] (#2.center)
-- cycle;
}

\def\tikz@lib@rightangle@foreground#1--#2--#3\pgf@stop{%
\path [name prefix ..] [pic actions, fill=none, shade=none]
\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
\expandafter\pgf@temp\expandafter[\tikzpictextoptions]{\tikzpictext};%
\fi
}
\makeatother

\begin{document}
\begin{tikzpicture}
\draw  (4,1) coordinate (C)
-- (0,0) coordinate (A)
-- ([turn] 0,3) coordinate (B)
-- cycle
pic [draw,red,"$\cdot$",angle eccentricity=.5]   {right angle = B--A--C}
pic [draw,blue,thick]  {right angle = A--C--B}
pic [fill=green,draw] {right angle = C--B--A};
;
\end{tikzpicture}
\end{document}


Note : I have created a rightangles library, available at GitHub that can be used in place of this hack like this

\documentclass[tikz,border=7pt]{standalone}
\usetikzlibrary{rightangles, quotes}

\begin{document}
\begin{tikzpicture}
\draw  (4,1) coordinate (C)
-- (0,0) coordinate (A)
-- ([turn] 0,3) coordinate (B)
-- cycle
pic [draw,red,"$\cdot$",angle eccentricity=.5]   {right angle = B--A--C}
pic [draw,blue,thick]  {right angle = A--C--B}
pic [fill=green,draw] {right angle = C--B--A};
;
\end{tikzpicture}
\end{document}

• Best answer! The main one does not work for rotated angles! ;) Jun 16 '18 at 22:07

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}