Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to have an image take up as much as possible of the content area in a beamer presentation, without overlapping the title, the sidebars, or the footers. How can I achieve this?

The code below gives an example of what goes wrong using \includegraphics and setting the width and height from \textwidth and \textheight -- if you try it, you'll see that the footer at the bottom is covered.

One can, of course, do something like height=0.9\textheight but that is annoying and not particularly robust if one changes themes... I'm looking for a more elegant solution.

\documentclass{beamer}
\mode<presentation>{
  \usetheme{Marburg}
}
\usepackage[utf8x]{inputenc}

\begin{document}
\begin{frame}{Header}{Sub title}
  \includegraphics[width=\textwidth,height=\textheight]{tmp.jpg}
\end{frame}
\end{document}
share|improve this question
    
Somewhat related question (the problem is the same, however no really satisfactory solution was provided): Automatically scale big and small graphics for beamer presentations –  diabonas Feb 11 '12 at 23:20
1  
The post [tex.stackexchange.com/questions/1858/… also provides references to \beamer@frametextheight but I haven't been able to figure out how to get it to work –  Mark Feb 12 '12 at 6:55
    
Great! \beamer@frametextheight seems like a good way to go. I had two problems with it: 1. It seems to be defined too late, when beamer actually typesets the slide. So in order to use it, you'll have to define your own version of the macro emulating its behaviour. 2. It only into account the height of the title, not the height of head- or footlines. –  diabonas Feb 12 '12 at 13:36
add comment

1 Answer

The following code demonstrates how to include an image full-size. To customize it, simply change image.jpg to the file name of the picture you want to display. If you're using a beamer theme without a sidebar (such as the default one, Ilmenau, AnnArbor, ...), alter \sidebarthemetrue to \sidebarthemefalse.

\documentclass{beamer}

\usetheme{Marburg}
\setbeamertemplate{navigation symbols}{}

\newif\ifsidebartheme
\sidebarthemetrue

\newdimen\contentheight
\newdimen\contentwidth
\newdimen\contentleft
\newdimen\contentbottom
\makeatletter
\newcommand*{\calculatespace}{%
\contentheight=\paperheight%
\ifx\beamer@frametitle\@empty%
    \setbox\@tempboxa=\box\voidb@x%
  \else%
    \setbox\@tempboxa=\vbox{%
      \vbox{}%
      {\parskip0pt\usebeamertemplate***{frametitle}}%
    }%
    \ifsidebartheme%
      \advance\contentheight by-1em%
    \fi%
  \fi%
\advance\contentheight by-\ht\@tempboxa%
\advance\contentheight by-\dp\@tempboxa%
\advance\contentheight by-\beamer@frametopskip%
\ifbeamer@plainframe%
\contentbottom=0pt%
\else%
\advance\contentheight by-\headheight%
\advance\contentheight by\headdp%
\advance\contentheight by-\footheight%
\advance\contentheight by4pt%
\contentbottom=\footheight%
\advance\contentbottom by-4pt%
\fi%
\contentwidth=\paperwidth%
\ifbeamer@plainframe%
\contentleft=0pt%
\else%
\advance\contentwidth by-\beamer@rightsidebar%
\advance\contentwidth by-\beamer@leftsidebar\relax%
\contentleft=\beamer@leftsidebar%
\fi%
}
\makeatother

\begin{document}
{
\setbeamertemplate{background canvas}{%
\calculatespace%
\begin{pgfpicture}
    \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{\paperheight}}
    \pgftext[at=\pgfpoint{\contentleft+0.5\contentwidth}{\contentbottom+0.5\contentheight}]{\includegraphics[width=\contentwidth,height=\contentheight]{image.jpg}}
\end{pgfpicture}%
}
\begin{frame}{Header}{Sub title}
Frame content
\end{frame}
}
\end{document}

Result:

Output result: A full sized-image

(The image used is by Steve Peter and can be downloaded at http://www.tug.org/publicity/wallpaper/.)


Explanation of the code:

1. Calculating the space available to content

These dimensions will hold the height and width available and the absolute position of the content in relation to the lower left corner of the page (which is necessary when there is a left sidebar or a footline):

\newdimen\contentheight
\newdimen\contentwidth
\newdimen\contentleft
\newdimen\contentbottom

Themes with sidebars, such as Marburg, require some extra treatment, as there's a \vskip-1em in the definition of the frametitle template which distorts the calculations:

\newif\ifsidebartheme
\sidebarthemetrue

The macro \calculatespace is the core piece which computes all the lengths defined above:

\makeatletter
\newcommand*{\calculatespace}{%

We begin with \paperheight and subtract the height of the frame title and subtitle (code adapted from beamerbaseframe.sty, ll. 114-129):

\contentheight=\paperheight%
\ifx\beamer@frametitle\@empty%
    \setbox\@tempboxa=\box\voidb@x%
  \else%
    \setbox\@tempboxa=\vbox{%
      \vbox{}%
      {\parskip0pt\usebeamertemplate***{frametitle}}%
    }%
    \ifsidebartheme%
      \advance\contentheight by-1em%
    \fi%
  \fi%
\advance\contentheight by-\ht\@tempboxa%
\advance\contentheight by-\dp\@tempboxa%
\advance\contentheight by-\beamer@frametopskip%

If it is a plain frame, this is everything that has to be taken into account. Otherwise, also subtract the height of head- and footline (cf. beamerbaseframecomponents.sty, ll. 161-182):

\ifbeamer@plainframe%
\contentbottom=0pt%
\else%
\advance\contentheight by-\headheight%
\advance\contentheight by\headdp%
\advance\contentheight by-\footheight%
\advance\contentheight by4pt%
\contentbottom=\footheight%
\advance\contentbottom by-4pt%
\fi%

Like this, we have calculated \contentheight and \contentbottom. To obtain the content width, one has to subtract the width of the sidebars from \paperwidth if it's not a plain frame (beamerbaseframesize.sty, ll. 80-85):

\contentwidth=\paperwidth%
\ifbeamer@plainframe%
\contentleft=0pt%
\else%
\advance\contentwidth by-\beamer@rightsidebar%
\advance\contentwidth by-\beamer@leftsidebar\relax%
\contentleft=\beamer@leftsidebar%
\fi%

2. Displaying the image

We now have a macro \calculatespace that computes all the necessary dimensions. It has to be called separately for each frame as the dimensions might change depending on whether you use titles and subtitles. The inclusion of the image is done in the background canvas template. It is scaled to the full width and height available and placed in the middle of the content space:

\setbeamertemplate{background canvas}{%
\calculatespace%
\begin{pgfpicture}
    \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{\paperheight}}
    \pgftext[at=\pgfpoint{\contentleft+0.5\contentwidth}{\contentbottom+0.5\contentheight}]{\includegraphics[width=\contentwidth,height=\contentheight]{image.jpg}}
\end{pgfpicture}%
}

If you don't want the image to be distorted, simply add keepaspectratio as an optional argument to \includegraphics.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.