[Tex/LaTex] “Grid” of background images in Beamer frame

backgroundsbeamer

I am trying to get a 2×2 grid of background images in a Beamer frame. I'd like the images to touch on all side (i.e., no whitespace around images). I am able to get a tabular environment inside \usebackgroundtemplate{}, but I have to play with negative \hspace{} to eliminate the left "margin" (feels like a hack). The problem is that the top row of images is behind the Beamer titles. When I use a single background image, I am able to use something like \includegraphics[width=\paperwidth,height=\paperheight,trim=0cm 0cm
0cm -5cm,clip]{image.jpg}}
to push the image down below the Beamer titles. That also feels like a hack, but it works. However, I can't figure out how to do something similar with the tabular environment. A MWE follows which also contains an attempt at using minipage environments, but all images end up in the same row despite trying many iterations of \linebreak, \pagebreak, etc.:

\documentclass{beamer}

\usetheme{Madrid}
\usecolortheme{default}
\usefonttheme[onlylarge]{structurebold}
\useinnertheme{rectangles}
\useoutertheme{smoothbars}
\setbeamertemplate{navigation symbols}{}

% Code for placeholder images
\makeatletter
  \AtBeginDocument{%
    \def\Ginclude@graphics#1{%
      \begingroup\fboxsep=-\fboxrule
      \fbox{\rule{\@ifundefined{Gin@@ewidth}{150pt}{\Gin@@ewidth}}{0pt}%
        \rule{0pt}{\@ifundefined{Gin@@eheight}{100pt}{\Gin@@eheight}}}\endgroup}}
\makeatother

\usepackage{graphicx}

\begin{document}
\usebackgroundtemplate{%
\def\arraystretch{0}
\renewcommand{\tabcolsep}{0cm}
\hspace*{-0.4cm}
\begin{tabular}{@{}cc@{}}
    \includegraphics[width=0.5\paperwidth,height=0.5\paperheight]{} &
    \includegraphics[width=0.5\paperwidth,height=0.5\paperheight]{} \\
    \includegraphics[width=0.5\paperwidth,height=0.5\paperheight]{} &
    \includegraphics[width=0.5\paperwidth,height=0.5\paperheight]{} \\
\end{tabular}
}
\begin{frame}
  \frametitle{Using tabular...}
\end{frame}
\usebackgroundtemplate{}

\usebackgroundtemplate{%
\begin{minipage}{1.0\paperwidth}
  \includegraphics[width=0.5\paperwidth,height=0.5\paperheight]{}
  \includegraphics[width=0.5\paperwidth,height=0.5\paperheight]{}
\end{minipage}
\begin{minipage}{1.0\paperwidth}
  \includegraphics[width=0.5\paperwidth,height=0.5\paperheight]{}
  \includegraphics[width=0.5\paperwidth,height=0.5\paperheight]{}
\end{minipage}
}
\begin{frame}
  \frametitle{Using minipage...} % All images end up on one line...
\end{frame}
\usebackgroundtemplate{}

\end{document}

Result

Image posted by JLDiaz

Best Answer

The \hspace "hack" can be easily avoided; you are leaving spurious blank spaces in your code; suppress them by using % right after \def\arraystretch{0} and \setlength{\tabcolsep}{0cm}.

To place your grid, you can use TikZ with a \node containing the tabular array of images; the width of each image will be 0.5\paperwidth; the tricky part is to calculate the precise height; the obvious choice, 0.5\textheight (and not 0.5\paperheight), won't be a good choice since it doesn't take into account the height of the frametitle box, so the height will be 0.5\textheight-0.5\ftht, where \ftht represents the height of the frametitle box.

TikZ will then be used to place the node at ( $ (current page.center) + (0,-\ftht) $ ); using \ftht in all the calculations will allow you to make the necessary adjustments (for example, if there's a theme change affecting the height of the default frametitle box) by simply making one change in the code. For example, for the Madrid theme the approximate value (obtained through trial/error) was 4ex:

\documentclass{beamer}
\usetheme{Madrid}
\usecolortheme{default}
\usefonttheme[onlylarge]{structurebold}
\useinnertheme{rectangles}
\useoutertheme{smoothbars}
\setbeamertemplate{navigation symbols}{}

\usepackage{tikz}
\usetikzlibrary{calc}

\newlength\ftht
\setlength\ftht{4ex}

% Code for placeholder images
\makeatletter
  \AtBeginDocument{%
    \def\Ginclude@graphics#1{%
      \begingroup\fboxsep=-\fboxrule
      \fbox{\rule{\@ifundefined{Gin@@ewidth}{150pt}{\Gin@@ewidth}}{0pt}%
        \rule{0pt}{\@ifundefined{Gin@@eheight}{100pt}{\Gin@@eheight}}}\endgroup}}
\makeatother

\begin{document}

\usebackgroundtemplate{%
\begin{tikzpicture}[remember picture,overlay]
\node at ( $ (current page.center) + (0,-\ftht) $ )
{
\def\arraystretch{0}%
\setlength\tabcolsep{0cm}%
\begin{tabular}[t]{cc}
    \includegraphics[width=0.5\paperwidth,height=\dimexpr0.5\textheight-0.5\ftht\relax]{} &
    \includegraphics[width=0.5\paperwidth,height=\dimexpr0.5\textheight-0.5\ftht\relax]{} \\
    \includegraphics[width=0.5\paperwidth,height=\dimexpr0.5\textheight-0.5\ftht\relax]{} &
    \includegraphics[width=0.5\paperwidth,height=\dimexpr0.5\textheight-0.5\ftht\relax]{} \\
\end{tabular}%
};
\end{tikzpicture}%
}

\begin{frame}
\frametitle{Using tabular}
\end{frame}

\end{document}

enter image description here

Unfortunately, if a frame has a two line title (or no title), the value for \ftht will have to be changed.