# beamer: How to place images behind text (z-order)

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?

-

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}
\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.

### 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.

-
Cool, thanks for the solution! EDIT: Sadly, this still seems to interfere with our beamer style. With default styles it works nicely, but with the official style the background block always seems to be empty; or -what I assume- it is behind the background which is probably a tikz rectangle spanning the slide. –  shiin Sep 23 '13 at 11:08
@shiin That's a pity :-( Please try adding my code (between \makeatletter and \makeatother) after loading your corporate theme with \usetheme to ensure that these changes aren't overwritten. If that doesn't work, you can try changing \addtobeamertemplate{background}{\box\@backgroundblock}{} to \addtobeamertemplate{headline}{\box\@backgroundblock}{} in l. 16 as a last ressort (this also has to be done after loading the corporate theme). –  diabonas Sep 23 '13 at 12:13
Thanks for the additional tips. Putting the code after loading our theme didn't work. Adding to the headline template instead of the background template shows the images, but they are again on top of the text. As this was quite frustrating, I played around with our theme and your code. In the end, I found that I simply had to move the backgroundblock up by one slide height, as it was added right below (vertically speaking) our background that spans the entire slide. –  shiin Sep 24 '13 at 7:58