How to add length and right angle to triangle

The following creates a triangle.

Q1. How can I add lengths such as 5cm, 6cm and xcm for each side.

Q2. How can I add a right angle sign to A?

 \item[b)]
\begin{tikzpicture}
% Draw the triangle
\draw[fill=gray!10]  (0, 0) coordinate (A)
-- (0,5) coordinate (C)
-- (6,0) coordinate (B)
-- (0, 0);

% Draw nodes
\node at (A)[anchor=north] {A};
\node at (B)[anchor=north] {B};
\node at (C)[anchor=south] {C};
\end{tikzpicture}


One option:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
% Draw the triangle
\draw[fill=gray!10]  (0, 0) coordinate (A)
-- node[left] {$3$\,cm} (0,5) coordinate (C)
-- node[above right] {$5$\,cm} (6,0) coordinate (B)
-- node[below] {$4$\,cm}  (0, 0);
\draw (0,10pt) -- ++(10pt,0) -- ++(0,-10pt);
% Draw nodes
\node at (A)[anchor=north] {$A$};
\node at (B)[anchor=north] {$B$};
\node at (C)[anchor=south] {$C$};
\end{tikzpicture}

\end{document}


Using a brace decoration, you could add braces to the sides to indicate the lengths:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}

\begin{tikzpicture}
% Draw the triangle
\draw[fill=gray!10]  (0, 0) coordinate (A)
-- (0,5) coordinate (C)
-- (6,0) coordinate (B)
-- (0, 0);
\draw[decoration={brace,mirror,raise=2pt},decorate]
(A) -- node[below=4pt] {$4$\,cm} (B);
\draw[decoration={brace,mirror,raise=2pt},decorate]
(B) -- node[above=4pt,sloped] {$5$\,cm} (C);
\draw[decoration={brace,mirror,raise=2pt},decorate]
(C) -- node[left=4pt] {$3$\,cm} (A);

\draw (0,10pt) -- ++(10pt,0) -- ++(0,-10pt);
% Draw nodes
\node at (A)[anchor=north] {$A$};
\node at (B)[anchor=north] {$B$};
\node at (C)[anchor=south] {$C$};
\end{tikzpicture}

\end{document}


• \draw (0,10pt) -- ++(10pt,0) -- ++(0,-10pt);draws an angle, but these coordinates, - and + doesn't make any sense to me. How do you decide these?
– shin
May 5, 2014 at 22:07
• @shin Those draw two sides of a square of side 10pt. The drawing begins at the point (0,10pt) then go 10pt to the right, and finally 10pt downwards. May 5, 2014 at 22:09
• @shin These indicate relative coordinates as opposed to absolute coordinates. May 5, 2014 at 22:17
• @shin the ++ modifier adds the coordinates to the previous point and locate the origin in the given coordinate. From the PGF manual: You can add a single + sign in front of a coordinate or two of them as in +(1cm,0cm) or ++(0cm,2cm). Such coordinates are interpreted differently: The first form means “1cm upwards from the previous specified position” and the second means “2cm to the right of the previous specified position, making this the new specified position. May 5, 2014 at 22:18