# How to add a transparent shadow to a block in beamer?

\documentclass{beamer}

\setbeamertemplate{background canvas}{\includegraphics[height=\paperheight]{example-image}}

% use rounded blocks with shadow

\begin{document}
\begin{frame}
\frametitle{Block with shadow and with background image}

Content...
\end{block}
\end{frame}
\end{document}


The (poor) result:

Edit: beamer offered this feature for some time, but it is incompatible with the latex-dvips-ps2pdf route. I suppose this feature could be optional...

-
Do you want just the shadow to have transparency or the complete block? –  Gonzalo Medina Sep 24 '12 at 23:45
@GonzaloMedina Just the shadow... as a real shadow! ;-) –  Paul Gaborit Sep 24 '12 at 23:46
Some good considerations are in Faded drop-shadow using tikz-based rounded rectangle? –  Paul Gaborit Sep 24 '12 at 23:52
beamer offered this feature for some time, but it is incompatible with the latex-dvips-ps2pdf route –  Paul Gaborit Sep 25 '12 at 5:49

A possible first approach, redefining \beamerboxesrounded and \endbeamerboxesrounded (as defined in beamerbaseboxes.sty) to use a change of opacity through \pgfsetfillopacity; the lines of code that were included are marked with % NEW; the desired opacity can be changed using the \opacity command (initially set to 0.5):

\documentclass{beamer}
\usepackage{tikz}

\newcommand\opacity{0.5}

\makeatletter
\renewcommand\beamerboxesrounded[2][]{%
\global\let\beamer@firstlineitemizeunskip=\relax%
\vbox\bgroup%
\setkeys{beamerboxes}{#1}%
{%
\usebeamercolor{\bmb@lower}%
\globalcolorstrue%
\colorlet{lower.bg}{bg}%
}%
{%
\usebeamercolor{\bmb@upper}%
\globalcolorstrue%
\colorlet{upper.bg}{bg}%
}%
%
%
\vskip4bp
\setbox\bmb@box=\hbox{%
\begin{minipage}[b]{\bmb@width}%
\usebeamercolor[fg]{\bmb@upper}%
#2%
\end{minipage}}%
\ifdim\wd\bmb@box=0pt%
\setbox\bmb@box=\hbox{}%
\ht\bmb@box=1.5pt%
\bmb@prevheight=-4.5pt%
\else%
\wd\bmb@box=\bmb@width%
\bmb@temp=\dp\bmb@box%
\ifdim\bmb@temp<1.5pt%
\bmb@temp=1.5pt%
\fi%
\setbox\bmb@box=\hbox{\raise\bmb@temp\hbox{\box\bmb@box}}%
\dp\bmb@box=0pt%
\bmb@prevheight=\ht\bmb@box%
\fi%
\bmb@temp=\bmb@width%
\hbox{%
\begin{pgfpicture}{0bp}{+-\ht\bmb@box}{0bp}{+-\ht\bmb@box}
\ifdim\wd\bmb@box=0pt%
\color{lower.bg}%
\else%
\color{upper.bg}%
\fi%
\pgfpathqmoveto{-4bp}{-1bp}
\pgfpathqcurveto{-4bp}{1.2bp}{-2.2bp}{3bp}{0bp}{3bp}
\pgfpathlineto{\pgfpoint{\bmb@temp}{3bp}}
\pgfpathcurveto%
{\pgfpoint{\bmb@dima}{3bp}}%
{\pgfpoint{\bmb@dimb}{1.2bp}}%
{\pgfpoint{\bmb@dimb}{-1bp}}%
\bmb@dima=-\ht\bmb@box%
\pgfpathlineto{\pgfpoint{\bmb@dimb}{\bmb@dima}}
\pgfpathlineto{\pgfpoint{-4bp}{\bmb@dima}}
\pgfusepath{fill}
\end{pgfpicture}%
\copy\bmb@box%
}%
\nointerlineskip%
\vskip-1pt%
\ifdim\wd\bmb@box=0pt%
\else%
\hbox{%
\begin{pgfpicture}{0pt}{0pt}{\bmb@width}{6pt}
\bmb@dima=\bmb@width%
\pgfpathrectangle{\pgfpoint{-4bp}{-1bp}}{\pgfpoint{\bmb@dima}{8bp}}
\pgfusepath{clip}
\end{pgfpicture}%
}%
\nointerlineskip%
\vskip-0.5pt%
\fi%
\pgfsetfillopacity{\opacity}% NEW
\fi%
\setbox\bmb@colorbox=\hbox{{\pgfpicturetrue\pgfsetcolor{lower.bg}}}%
\setbox\bmb@box=\hbox\bgroup\begin{minipage}[b]{\bmb@width}%
\pgfsetfillopacity{1}% NEW
\vskip2pt%
\usebeamercolor[fg]{\bmb@lower}%
\colorlet{beamerstructure}{upper.bg}%
\colorlet{structure}{upper.bg}%
%\color{.}%
}

\def\endbeamerboxesrounded{%
\end{minipage}\egroup%
\wd\bmb@box=\bmb@width%
\bmb@temp=\dp\bmb@box%
\setbox\bmb@box=\hbox{\raise\bmb@temp\hbox{\box\bmb@box}}%
\dp\bmb@box=0pt%
\bmb@temp=\wd\bmb@box%
\hbox{%
\begin{pgfpicture}{0bp}{0bp}{0bp}{0bp}
\begin{pgfscope}
{%
\pgfsetfillopacity{1}% NEW
\pgfpathrectangle{\pgfpoint{\bmb@temp}{-7bp}}{\pgfpoint{9bp}{9bp}}%
\pgfusepath{clip}
}%
\end{pgfscope}
\begin{pgfscope}
\pgfsetfillopacity{\opacity}% NEW
\pgfpathrectangle{\pgfpoint{4bp}{-7bp}}{\pgfpoint{\bmb@temp}{5bp}}
\pgfusepath{clip}
\end{pgfscope}
\begin{pgfscope}
\pgfsetfillopacity{\opacity}% NEW
\bmb@dima=\ht\bmb@box%
\pgfpathrectangle{\pgfpoint{\bmb@temp}{1bp}}{\pgfpoint{4bp}{\bmb@dima}}
\pgfusepath{clip}
\pgfpathrectangle{\pgfpoint{\bmb@temp}{1bp}}{\pgfpoint{4bp}{\bmb@dima}}
\pgfusepath{clip}
{\pgftransformshift{\pgfpoint{\bmb@temp}{-3bp}}%
\pgftransformrotate{90}%
\end{pgfscope}
\fi%
\pgfsetfillopacity{1}% NEW
\unhbox\bmb@colorbox%
\pgfpathqmoveto{-4bp}{1bp}
\pgfpathqcurveto{-4bp}{-1.2bp}{-2.2bp}{-3bp}{0bp}{-3bp}
\pgfpathlineto{\pgfpoint{\the\bmb@temp}{-3bp}}
\pgfpathcurveto%
{\pgfpoint{\the\bmb@dima}{-3bp}}%
{\pgfpoint{\the\bmb@dimb}{-1.2bp}}%
{\pgfpoint{\the\bmb@dimb}{1bp}}%
{
\bmb@dima=\ht\bmb@box%
\pgfpathlineto{\pgfpoint{\bmb@dimb}{\bmb@dima}}
\pgfpathlineto{\pgfpoint{-4bp}{\bmb@dima}}
\pgfusepath{fill}
}
{
\color{black!50!bg}
\pgfsetlinewidth{0pt}
\pgfpathmoveto{\pgfpoint{\bmb@dimb}{-.5bp}}
\bmb@dima=\ht\bmb@box%
\pgfpathlineto{\pgfpoint{\bmb@dimb}{\bmb@dima}}
\pgfusepath{stroke}
\bmb@temp=\bmb@dima
\color{black!31!bg}
\pgfpathmoveto{\pgfpoint{\bmb@dimb}{\bmb@temp}}
\pgfpathlineto{\pgfpoint{\bmb@dimb}{\bmb@dima}}
\pgfusepath{stroke}
\color{black!19!bg}
\pgfpathmoveto{\pgfpoint{\bmb@dimb}{\bmb@temp}}
\pgfpathlineto{\pgfpoint{\bmb@dimb}{\bmb@dima}}
\pgfusepath{stroke}
\color{black!6!bg}
\pgfpathmoveto{\pgfpoint{\bmb@dimb}{\bmb@temp}}
\pgfpathlineto{\pgfpoint{\bmb@dimb}{\bmb@dima}}
\pgfusepath{stroke}
\color{bg}
\pgfpathmoveto{\pgfpoint{\bmb@dimb}{\bmb@temp}}
\pgfpathlineto{\pgfpoint{\bmb@dimb}{\bmb@dima}}
\pgfusepath{stroke}
}
\fi
\end{pgfpicture}%
\box\bmb@box%
}%
\vskip4bp minus 2bp%
\else%
\vskip2bp%
\fi%
\egroup% of \vbox\bgroup
}
\makeatother

% background image
\setbeamertemplate{background canvas}{%
\tikz[remember picture,overlay]%
\node at (current page) {\includegraphics[height=\paperheight]{example-image}};
}

\begin{document}
\begin{frame}
\frametitle{Block with shadow and with background image}

Content...
\end{block}
\end{frame}
\end{document}


-

To get real transparency for box shadows with beamer, you could use this patch from the beamer repository. At this time, this patch is not included in beamer (see discussion).

If you use pdflatex, you can use the patched version of beamerbaseboxes.sty.

Here is the result of my MWE:

Here is the patched version of beamerbaseboxes.sty (put it in the same directory as your beamer document to get real transparency):

% Copyright 2003--2007 by Till Tantau
% Copyright 2010 by Vedran Mileti\'c
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%

\def\beamerboxesdeclarecolorscheme#1#2#3{% scheme name, upper color, lower color
\setbeamercolor{@scheme upper #1}{fg=white,bg={#2}}
\setbeamercolor{@scheme lower #1}{bg={#3}}
}

\define@key{beamerboxes}{scheme}{\def\bmb@upper{@scheme upper #1}\def\bmb@lower{@scheme lower #1}}
\define@key{beamerboxes}{upper}{\def\bmb@upper{#1}}
\define@key{beamerboxes}{lower}{\def\bmb@lower{#1}}
\define@key{beamerboxes}{width}{\edef\bmb@width{#1}}

\newbox\bmb@box
\newbox\bmb@colorbox
\newdimen\bmb@boxwidth
\newdimen\bmb@boxheight
\newdimen\bmb@prevheight
\newdimen\bmb@temp
\newdimen\bmb@dima
\newdimen\bmb@dimb

\newcommand\beamerboxesrounded[2][]{%
\global\let\beamer@firstlineitemizeunskip=\relax%
\vbox\bgroup%
\setkeys{beamerboxes}{#1}%
{%
\usebeamercolor{\bmb@lower}%
\globalcolorstrue%
\colorlet{lower.bg}{bg}%
}%
{%
\usebeamercolor{\bmb@upper}%
\globalcolorstrue%
\colorlet{upper.bg}{bg}%
}%
%
%
\vskip4bp
\setbox\bmb@box=\hbox{%
\begin{minipage}[b]{\bmb@width}%
\usebeamercolor[fg]{\bmb@upper}%
#2%
\end{minipage}}%
\ifdim\wd\bmb@box=0pt%
\setbox\bmb@box=\hbox{}%
\ht\bmb@box=1.5pt%
\bmb@prevheight=-4.5pt%
\else%
\wd\bmb@box=\bmb@width%
\bmb@temp=\dp\bmb@box%
\ifdim\bmb@temp<1.5pt%
\bmb@temp=1.5pt%
\fi%
\setbox\bmb@box=\hbox{\raise\bmb@temp\hbox{\box\bmb@box}}%
\dp\bmb@box=0pt%
\bmb@prevheight=\ht\bmb@box%
\fi%
\bmb@temp=\bmb@width%
\hbox{%
\begin{pgfpicture}{0bp}{+-\ht\bmb@box}{0bp}{+-\ht\bmb@box}
\ifdim\wd\bmb@box=0pt%
\color{lower.bg}%
\else%
\color{upper.bg}%
\fi%
\pgfpathqmoveto{-4bp}{-1bp}
\pgfpathqcurveto{-4bp}{1.2bp}{-2.2bp}{3bp}{0bp}{3bp}
\pgfpathlineto{\pgfpoint{\bmb@temp}{3bp}}
\pgfpathcurveto%
{\pgfpoint{\bmb@dima}{3bp}}%
{\pgfpoint{\bmb@dimb}{1.2bp}}%
{\pgfpoint{\bmb@dimb}{-1bp}}%
\bmb@dima=-\ht\bmb@box%
\pgfpathlineto{\pgfpoint{\bmb@dimb}{\bmb@dima}}
\pgfpathlineto{\pgfpoint{-4bp}{\bmb@dima}}
\pgfusepath{fill}
\end{pgfpicture}%
\copy\bmb@box%
}%
\nointerlineskip%
\vskip-1pt%
\ifdim\wd\bmb@box=0pt%
\else%
\hbox{%
\begin{pgfpicture}{0pt}{0pt}{\bmb@width}{6pt}
\bmb@dima=\bmb@width%
\pgfpathrectangle{\pgfpoint{-4bp}{-1bp}}{\pgfpoint{\bmb@dima}{8bp}}
\pgfusepath{clip}
{%
\pgftransformshift{\pgfpoint{-4bp}{0bp}}%
}%
\end{pgfpicture}%
}%
\nointerlineskip%
\vskip-0.5pt%
\fi%
\setbox\bmb@colorbox=\hbox{{\pgfpicturetrue\pgfsetcolor{lower.bg}}}%
\setbox\bmb@box=\hbox\bgroup\begin{minipage}[b]{\bmb@width}%
\vskip2pt%
\usebeamercolor[fg]{\bmb@lower}%
\colorlet{beamerstructure}{upper.bg}%
\colorlet{structure}{upper.bg}%
%\color{.}%
}

\def\endbeamerboxesrounded{%
\end{minipage}\egroup%
\bmb@temp=\dp\bmb@box%
\setbox\bmb@box=\hbox{\raise\bmb@temp\hbox{\box\bmb@box}}%
\dp\bmb@box=0pt%
\bmb@boxwidth=\bmb@width%
\bmb@boxheight=\ht\bmb@box%
{%
color(0bp)=(pgftransparent!50);
color(4bp)=(pgftransparent!100)
}%
{%
color(0bp)=(pgftransparent!0);
color(8bp)=(pgftransparent!100)
}%
{%
color(0bp)=(pgftransparent!0);
color(8bp)=(pgftransparent!100)
}%
{%
color(0bp)=(pgftransparent!100);
color(8bp)=(pgftransparent!0)
}%
{%
\begin{pgfpicture}
%
% clipping is needed because shadow is typeset on top of box
\begin{pgfscope}
\pgfsetcolor{black}
\pgfpathrectangle{\pgfpoint{4bp}{8bp}}{\pgfpoint{\bmb@boxwidth-0.2bp}{\bmb@boxheight-2bp}}
\pgfusepath{fill}
\end{pgfscope}
\end{pgfpicture}
}%
\fi%
\bmb@temp=\bmb@width%
\hbox{%
\begin{pgfpicture}{0bp}{0bp}{0bp}{0bp}
\begin{pgfscope}
\pgfpathrectangle{\pgfpoint{0bp}{-7bp}}
{\pgfpoint{\bmb@boxwidth+8bp}{\bmb@boxheight+6bp}}
\pgftransformshift{\pgfpoint{0.5\bmb@boxwidth+6bp}{0.5\bmb@boxheight-4bp}}}
\pgfusepath{fill}
\end{pgfscope}
\fi%
\unhbox\bmb@colorbox%
\pgfpathqmoveto{-4bp}{1bp}
\pgfpathqcurveto{-4bp}{-1.2bp}{-2.2bp}{-3bp}{0bp}{-3bp}
\pgfpathlineto{\pgfpoint{\the\bmb@temp}{-3bp}}
\pgfpathcurveto%
{\pgfpoint{\the\bmb@dima}{-3bp}}%
{\pgfpoint{\the\bmb@dimb}{-1.2bp}}%
{\pgfpoint{\the\bmb@dimb}{1bp}}%
{
\bmb@dima=\ht\bmb@box%
\pgfpathlineto{\pgfpoint{\bmb@dimb}{\bmb@dima}}
\pgfpathlineto{\pgfpoint{-4bp}{\bmb@dima}}
\pgfusepath{fill}
}
\end{pgfpicture}%
\box\bmb@box%
}%
\vskip4bp minus 2bp%
\else%
\vskip2bp%
\fi%
\egroup% of \vbox\bgroup
}

%