7

I am trying to get a 2x2 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

3
  • Welcome! I posted the image for you.
    – JLDiaz
    Mar 17, 2013 at 23:36
  • Yet another hack: put a first row in your table, before the figures , with: \\[6mm]
    – JLDiaz
    Mar 17, 2013 at 23:40
  • 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}. Mar 18, 2013 at 2:25

1 Answer 1

5

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.

6
  • See Set image to full all available space in Beamer (without overlapping other elements) for a (partly) automated calculation of the necessary dimensions: It still requires some adjustments for each theme (e.g. in this particular example, one would additionally have to take the shading of the smoothbars theme into account), but it should handle things like header or title height changes automatically in most cases.
    – diabonas
    Mar 18, 2013 at 12:10
  • This certainly works! I'm not sure I understand why setting the node position at $ (current page.center) + (0,-\ftht) $ works, though. This is setting the location of the tabular environment... but seems to be locating a point "top-center" of the usable frame space (tikz coordinates are [X,Y], correct?) I would have expected the coordinate to be "top-left", but perhaps I am not aware of how the tabular environment is laid out. Regardless, I was able to also make this solution work for a single image in the background, and was able to eliminate trim,clip options from \includegraphics
    – jjwebster
    Mar 18, 2013 at 14:12
  • @diabonas I tried that solution. I really like the idea of being able to automatically calculate the required offset, but my document fails to compile and halts at the call to the macro \calculatespace. I'm able to call each of the variables defined by the macro with \the\contentheight (for example), but all four report as 0.0pt. Do I need to do anything special to get the macro to compile? (I'm using Aquamacs+AUCTeX+PDFLatex)
    – jjwebster
    Mar 18, 2013 at 14:16
  • @jjwebster I am working on a solution using diabonas's answer, but some manual adjustments are still necessary in some cases. I'll add it in some minutes. Mar 18, 2013 at 14:20
  • @diabonas nice approach. I'll add some answer here using your idea, if you're OK with that. Mar 18, 2013 at 14:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .