I asked this question originally in attempt to get background images behind my code listings.
Background images for code listings
What I did not mention is that I am using the beamer package for slides. This technique does not seem to work with beamer. I get a gray box behind the code listing.
How do I get background images behind code listings in beamer? `
\documentclass{beamer}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand*{\AddBackgroundImage}[4][]{%
%\pgfmathsetmacrp{\height}{}%
\begin{tikzpicture}[overlay,remember picture]
\coordinate (VCenter) at ($(#2)!0.5!(#3)$);
\coordinate (Fudge) at (-\pgflinewidth,0);
\coordinate (VFudge) at (0,\baselineskip);
%\draw [red, thick,fill=yellow, fill opacity=0.2]% for debugging
\clip
($(#2)+ (Fudge) - 0.50*(VFudge)$) --
($(#2) + (\linewidth,0) - 0.50*(VFudge)$) --
($(#3) + (\linewidth,0) + 1.25*(VFudge)$) --
($(#3)+ (Fudge) + 1.25*(VFudge)$) -- cycle;
\path (VCenter) -- ++($(0.5*\linewidth,0)$)
node [opacity=0.3, #1] {\includegraphics[width=\linewidth]{#4}};
\end{tikzpicture}%
}%
\usetheme {default}
\lstset{ language=Haskell
, basicstyle=\small\sffamily
, numbers=left
, numberstyle=\tiny\color{gray}
}
\begin{document}
\begin{frame}[fragile]
\noindent% Line above MUST be blank
\tikzmark{Start}%
\begin{lstlisting}
data PersonRecord =
PersonRecord { firstname :: FirstName,
lastname :: LastName,
middleinitial :: Maybe MiddleInitial,
gender :: Gender,
favoritecolor :: FavoriteColor,
dateofbirth :: CalendarTime
} deriving (Show)
\end{lstlisting}
\end{frame}
\tikzmark{End}
\AddBackgroundImage{Start}{End}{images/black-screen}%
%
\noindent
Some text afterwards.
\end{document}