[Tex/LaTex] How to align a right angle

tikz-pgf

As you you can see in the following image, a right angle has some space to side BC.

How can I fix it and is there any better way to add an right angle?

enter image description here

\documentclass{article}
\usepackage{tikz}

\begin{document}
   \begin{tikzpicture}
      \draw[fill=gray!10]  (0, 4) coordinate (A) 
       -- node[above=4pt] {$4cm$} (3,4) coordinate (C) 
       -- node[right] {$8cm$} (3,0) coordinate (B) 
       -- node[left] {$xcm$}  (0, 4);
     \draw (2.6,4) -- ++(0,-10pt) -- ++(10pt,0);

        \node at (A)[anchor=east] {$A$};
        \node at (B)[anchor=north] {$B$};
        \node at (C)[anchor=south] {$C$};
      \end{tikzpicture}
\end{document}

Best Answer

Since the little square has side 10pt, you need to start 10pt to the left of C using, for example

([xshift=-10pt]C)

A complete example:

\documentclass{article}
\usepackage{tikz}

\begin{document}
   \begin{tikzpicture}
      \draw[fill=gray!10]  (0, 4) coordinate (A) 
       -- node[above=4pt] {$4$\, cm} (3,4) coordinate (C) 
       -- node[right] {$8$\,cm} (3,0) coordinate (B) 
       -- node[left] {$x$\,cm}  (0, 4);
     \draw ([xshift=-10pt]C) -- ++(0,-10pt) -- ++(10pt,0);

        \node at (A)[anchor=east] {$A$};
        \node at (B)[anchor=north] {$B$};
        \node at (C)[anchor=south] {$C$};
      \end{tikzpicture}
\end{document}

enter image description here

If you are going to do a lot of constructions like this one, I'd like to suggest you the tkz-euclide package; it has a very intuitive syntax and has a predefined command \tkzMarkRightAngle to easily mark the right angles:

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

\begin{document}

\begin{tikzpicture}
\tkzDefPoint(0,4){A}
\tkzDefPoint(3,4){C}
\tkzDefPoint(3,0){B}
\tkzDrawPolygon[fill=gray!10](A,B,C)
\tkzLabelPoints(B)
\tkzLabelPoints[left](A)
\tkzLabelPoints[right](C)
\tkzMarkRightAngle(B,C,A)
\tkzLabelSegment[above](A,C){$4$\,cm}
\tkzLabelSegment[left=4pt](B,A){$x$\,cm}
\tkzLabelSegment[right](C,B){$8$\,cm}
\end{tikzpicture}

\end{document}

enter image description here