[Tex/LaTex] beamer: How to place images behind text (z-order)

beamergraphics

When writing a beamer presentation, I often use textblocks containing a single includegraphics to place pictures freely on a slide, e.g.

\begin{textblock*}{0.51\textwidth}(10.8mm,56.8mm)
  \includegraphics[width=50mm]{picture}
\end{textblock*}

Unfortunately, images are alwyas placed above the textbody of the slide with respect to the z-order, i.e. the pictures overlap and cover the text. Sometimes this is very inconvenient, especially if the picture itself is not square-shaped.

I read about using beamer background templates as a solution, but this not work in my case. Our corporate beamer style also uses background templates which interferes with this solution. Moreover, using textblocks does not seem to work inside a beamer background template.

I also read about wrapping everything in tikz to get the correct z-order. But this additional layer code is also very inconvient when you need it on every other slide.

So, is there an easier solution to place pictures anywhere on the slide and have them behind the text?

Best Answer

You can define a custom environment backgroundblock like this:

\documentclass{beamer}

% For demonstration purposes only, can be removed without harm
\usetheme{Ilmenau}
\usepackage{lipsum}

% beamer: How to place images behind text (z-order)
% (http://tex.stackexchange.com/a/134311)
\makeatletter
\newbox\@backgroundblock
\newenvironment{backgroundblock}[2]{%
  \global\setbox\@backgroundblock=\vbox\bgroup%
    \unvbox\@backgroundblock%
    \vbox to0pt\bgroup\vskip#2\hbox to0pt\bgroup\hskip#1\relax%
}{\egroup\egroup\egroup}
\addtobeamertemplate{background}{\box\@backgroundblock}{}
\makeatother

\begin{document}
\begin{frame}
\begin{backgroundblock}{10mm}{10mm}
\includegraphics[width=50mm]{example-image-a}
\end{backgroundblock}
\lipsum
\begin{backgroundblock}{60mm}{47.5mm}
\includegraphics[width=50mm]{example-image-b}
\end{backgroundblock}
\end{frame}
\end{document}

It is used very much like the textpos environment textblock(*) in absolute mode, i. e.

\begin{backgroundblock}{<hpos>}{<vpos>}
<Content>
\end{backgroundblock}

places <Content> in a box at the coordinates (<hpos>,<vpos>) relative to the top left corner of the slide.

example slide with two backgroundblock environments

Explanation of the code

A box \@backgroundblock is added to the beamer template background which is later filled by the content of the backgroundblock environments. This shouldn't interfere with custom themes, as it is ensured that the box doesn't any occupy any space.