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.

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}
share|improve this question
    
With TikZ 3.0.0 and angles library, it is possible to use a small trick as per How do I draw a little red square to label my right triangle? –  Claudio Fiandrino May 6 at 6:58

2 Answers 2

up vote 8 down vote accepted

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

share|improve this answer

You can also use the right angle symbol style:

enter image description here

Notes:

References:

Code:

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

\tikzset{
    right angle quadrant/.code={
        \pgfmathsetmacro\quadranta{{1,1,-1,-1}[#1-1]}     % Arrays for selecting quadrant
        \pgfmathsetmacro\quadrantb{{1,-1,-1,1}[#1-1]}},
    right angle quadrant=1, % Make sure it is set, even if not called explicitly
    right angle length/.code={\def\rightanglelength{#1}},   % Length of symbol
    right angle length=2ex, % Make sure it is set...
    right angle symbol/.style n args={3}{
        insert path={
            let \p0 = ($(#1)!(#3)!(#2)$) in     % Intersection
                let \p1 = ($(\p0)!\quadranta*\rightanglelength!(#3)$), % Point on base line
                \p2 = ($(\p0)!\quadrantb*\rightanglelength!(#2)$) in % Point on perpendicular line
                let \p3 = ($(\p1)+(\p2)-(\p0)$) in  % Corner point of symbol
            (\p1) -- (\p3) -- (\p2)
        }
    }
}

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

    \draw [red,ultra thick, right angle quadrant=2,right angle symbol={B}{C}{A}];

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

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.