[Tex/LaTex] creating beamer frame templates

beamer

I am creating a beamer theme. As part of the theme, I would like to create some frame templates with specific layouts. The simplest of these is a static frame that includes a single graphic centered on a plain frame. I would like the user to be able to invoke this frame like this:

\documentclass[presentation]{beamer}
\usetheme{Zion}
\begin{frame}[getoffthestage]{}
\end{frame}

To implement this, I have included the following latex code in my beamer style file beamerthemeZion.sty.

\newif\ifbeamer@getoffthestage

\define@key{beamerframe}{getoffthestage}[true]{%
  \beamer@plainframetrue\beamer@getoffthestagetrue%
  \def\beamer@frametemplate{\beamer@frametemplate@plain}%
  \usebeamertemplate*{getoffthestage}}

\beamer@getoffthestagefalse

\defbeamertemplate*{getoffthestage}{}{%
\noindent\begin{minipage}[b][\textheight][c]{\textwidth}%
\hspace*{\fill}%
\includegraphics[height=0.4\paperheight]{logographic}%
\hspace*{\fill}%
\end{minipage}}

I have two questions:

First, why are the contents of the getoffthestage frame placed near the bottom of the slide? I am forced to use a minipage to vertically center the graphic.

Second, why does a minipage that is \textwidth wide cause an unwanted page break? When I make the width 0.9\textwidth, everything stays on one page.

I am guessing that I am putting the \usebeamertemplate* command in the wrong place. Is there a better way to do what I want?

Best Answer

The source of all your trouble is that everything you define in \define@key{beamerframe}{getoffthestage}[true]{...} is executed right before the frame start. So when your code is trying to insert the image etc. the frame is not yet opened which leads to the strange placement etc.

As an simple alternative I suggest to add your image to another beamertemplate, e.g. the background canvas or any other you do not need:

\documentclass{beamer}

\usepackage{etoolbox}
\BeforeBeginEnvironment{frame}{%
    \setbeamertemplate{background canvas}{}%
}

\makeatletter
\define@key{beamerframe}{getoffthestage}[true]{%
    \setbeamertemplate{background canvas}{%
        \vbox to \paperheight{\vfil\hbox to \paperwidth{\hfil\includegraphics[width=.5\textwidth]{example-grid-100x100bp}\hfil}\vfil}%
    }%
}
\makeatother

\begin{document}

\begin{frame}[getoffthestage]
\end{frame}

\begin{frame}
    \frametitle{bla}
    normal frame
\end{frame}

\end{document}
Related Question