57

For the next few semesters I'll be making a lot of beamer presentations with a lot slides that are just a frame title and a figure. I am trying to make a command to make a lot faster to code and easier to read. Here is my first attempt:

\usepackage{graphicx}

\newcommand {\framedgraphic}[2] {
\begin{frame}{#1}
    \begin{figure}
        \begin{center}
            \includegraphics{#2}
        \end{center}
    \end{figure}
\end{frame}
}

In this past I've have scaled manually with something like

\includegraphics[height=0.7\textheight]{table3a.png}

Through trial and error I have to find the right scaling to make the figure fill the slide. Is there a way I can automatically do this scaling without adding more arguments to my command? Including covering both wide and tall figures? Thanks!

BTW, here I'm using graphicx but I'm not really wed to it. I am just getting started in TeX and would love to learn any new ways of thinking of this problem.

lockstep
  • 250,273
  • 2
    I know that problem. The available height depends on the used beamer style. The fame title (and sub-title if present) counts as part of \textheight. AFAIK there is no length which stores the rest of the height. – Martin Scharrer Feb 24 '11 at 16:32
  • 3
    Note that the figure environment is for floating figures, which doesn't make sense in a presentation. They are not required for \includegraphics to work. Simply remove them here. – Martin Scharrer Feb 24 '11 at 16:55
  • 3
    Beamer defines \headheight and \footheight, but it seems that \textheight-\headheight-\footheight is bigger then the actual height you have available. – Caramdir Feb 24 '11 at 17:15
  • 3
    figure is not a floating environment inside beamer –  Feb 24 '11 at 21:41
  • @Martin, @Herbert -- Thanks! Any idea on scale to fit? – Richard Herron Feb 24 '11 at 22:27
  • 12
    Not more than \includegraphics[width=.95\textwidth,height=\myheight,keepaspectratio]{image} where \myheight = \textheight - some guessed value. – Martin Scharrer Feb 24 '11 at 22:53
  • @Martin -- Thanks! I didn't about keepaspectratio to take up the slack in the non-binding dimension. I'll post the solution as an edit above for you to cut in paste as a solution I can accept? – Richard Herron Feb 25 '11 at 03:37
  • @richardh: I think Martin won't object if you answer your question yourself, saying that you got the answer with Martin's help in the comments. Then you can accept your own answer (and remove the answer from the question, as it's best not to have answers in questions). – Hendrik Vogt Feb 25 '11 at 10:08

2 Answers2

59

Martin's comment had the fix. Here's what I'm using:

\newcommand {\framedgraphic}[2] {
    \begin{frame}{#1}
        \begin{center}
            \includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{#2}
        \end{center}
    \end{frame}
}
6

I've come across another solution to this problem that is slightly different because it takes up the entire page including margins. I have an analogous one for "fullheightgraphic" that uses \paperheight instead of paperwidth

\newcommand{\fullwidthgraphic}[2] {
   {
   \usebackgroundtemplate{\includegraphics[height=\paperwidth]{#1}}
   \begin{frame}{#2}
   \end{frame}
   }
}
JeremyKun
  • 243