[Tex/LaTex] Adding shadow over image

beamergraphicsoverlaystransparency

I'm making a beamer presentation and I'd like to first show an image in its true form:

fig

and in the next slide have it shown with a shadow over a part of it like so:

fig_w_shadow

Is there a way to do this?

Best Answer

Here is a very robust way of doing it:

enter image description here

\documentclass{beamer}% http://ctan.org/pkg/beamer
\newsavebox{\myimage}
\savebox{\myimage}{\quad\fbox{\includegraphics[width=150pt]{tiger}}\quad}% Store image with padding
\begin{document}
\begin{frame}
  \frametitle{A frame title}
  \onslide<2>{%
    \smash{% Remove vertical height
      \rlap{% Right overLAP (zero-width, left-aligned)
        \color{black!30}% Background colour
          \rule[\dimexpr-\ht\myimage-\baselineskip]{\wd\myimage}{.5\ht\myimage}% Box
          }}}%
  \usebox{\myimage}
\end{frame}
\end{document}

The idea is to print a block (\rule[<depth>]{<width>}{<height>}) of specific colour (\color{black!30} = 30% black) in the background of the image (stored in a box \myimage) that has zero width (\rlap) and height (\smash) and position it properly to only highlight the area you're after. The padding is used in \myimage (a \quad or \hspace*{1em} on both sides).

The overlay specification \onslide<.> prints the block only on slide 2. You would have to play with the measurements, since I don't have your image/chart.

Note: This requires your image (or chart) to be transparent so the block can be visible where nothing is drawn.


If you're after the reverse, and using some transparency in an overlay, then the following might be what you're after. Similar techniques are followed, only using the transparent package's \transparent{<num>} to specify the transparency of the colour used (0 = fully transparent; 1 = fully opaque):

enter image description here

\documentclass{beamer}% http://ctan.org/pkg/beamer
\usepackage{transparent}% http://ctan.org/pkg/transparent
\newsavebox{\myimage}
\savebox{\myimage}{\quad\fbox{\includegraphics[width=150pt]{tiger}}\quad}% Store image with padding
\begin{document}
\begin{frame}
  \frametitle{A frame title}
  \rlap{\usebox{\myimage}}%
  \onslide<2>{%
    \smash{% Remove vertical height
      \color{black}\transparent{0.8}% Overlay colour = black + 80% opaque
        \rule{\wd\myimage}{.5\ht\myimage}% Box
    }}%
\end{frame}
\end{document}