[Tex/LaTex] How to shade shapes in tikzpicture

tikz-pgf

I managed to draw the rectangle and a triangle inside with the below code.

\documentclass[]{article}
\usepackage{tikz}
\begin{document}


\begin{center}
\begin{tikzpicture}
\draw(0,0) rectangle (4,-3);
\draw(0,0) -- ++(4,-1.5) -- ++(-2,-1.5) -- ++(-2,3);
\draw[dotted](0,0) to[bend left] node[fill=white] {$2b$} (4,0);
\draw[dotted](0,0) to[bend right] node[fill=white] {$a$} (0,-3);
\end{tikzpicture}
\end{center}

\end{document}

result

Now I want to shade the triangle.
How would you go about doing this?

Thank you

Best Answer

Simple add fill=gray (or what ever color) into drawing a triangle, something like:

\documentclass[]{article}
\usepackage{tikz}

    \begin{document}
\begin{center}
\begin{tikzpicture}
\draw   (0,0) rectangle (4,-3);
\draw[fill=gray!30]    (0,0) -- ++(4,-1.5) -- ++(-2,-1.5) -- ++(-2,3);
\draw[dotted](0,0) to[bend left] node[fill=white] {$2b$} (4,0);
\draw[dotted](0,0) to[bend right] node[fill=white] {$a$} (0,-3);
\end{tikzpicture}
\end{center}
     \end{document}

enter image description here