[Tex/LaTex] how can I shade an area in a beamer frame

beamershading

I have a beamer frame, and I want to shade a whole area with some color – i.e. that the whole area (rectangular) will be using a single grey color switched from any color (except for white) appearing in this area. Is that possible? I don't mind if I have to play around with the coordinates of the area specification to get it right (i.e. it can be absolute positioning).

Just a note: if that's impossible (shading an area), I am willing also to settle for a whitespace holder in this area, that erases everything below.

EDIT: By shading I mean changing the color of the current content to grey, not the background.

EDIT 2: It seems like my question was not very clear. I have some packages that I am using (such as qtree). All of these are environment based, and are used as macros, and therefore they are hard to customize to make everything that appear in them grey. So what I want is to do re-draw on these areas and just replace every pixel which is non-white to a gray pixel. An alternative is to replace all pixels in a certain area in the frame to a white pixel (irregardless of its previous color). This seems much easier to do. It is just "re-positioning" a white rectangle on existing text/image.

I think the general idea of what I want to do might go against the rather hierarchical top-down structure of latex code, but it seems like a simple thing to ask for, so I thought it might be possible.

Best Answer

You ask for two different things:

1. Changing all the used (content) colors in a certain area to gray

For all code and packages that rely on xcolor to produce colored output, you can use \selectcolor{gray} in a group (i. e. wrapped in curly braces). Make sure to also issue \color{black} at the beginning of the group so that previous color changes are reverted. At the end of that group, the old color model will be restored automatically so that you're able to produce colorful output again:

\documentclass{beamer}
\begin{document}
\begin{frame}
\color{red} This is red text with {\color{blue} blue}, but {\selectcolormodel{gray}\color{black} from now on {\color{blue} all} \color{green} is grey.} Now it's colourful (red) again!
\end{frame}
\end{document}

output of the example code, showing how to change the content color of a certain area to gray

Note that this won't work for packages which have some color management of their own, e.g. directly setting the respective PDF properties.

2. Changing the background color of a certain area to white

This can be done in a number of ways, the easiest of which is probably wrapping the content of the area in a beamercolorbox:

\documentclass{beamer}
\setbeamercolor{normal text}{bg=gray!40}
\begin{document}
\begin{frame}
\setbeamercolor{whitebox}{bg=white}
\begin{beamercolorbox}[sep=2mm]{whitebox}
    This text is in a box with white backgound.
\end{beamercolorbox}
\end{frame}
\end{document}

output of the example code: a text in a white box

The size of the box can be controlled with the optional argument of beamercolorbox - in the example, a margin of 2mm is added to each side.

Related Question