Beamer Template – Customizing Frame Style Options in Beamer

beamerheader-footeroptional argumentstemplates

I am working on a beamer template which tries to mimick an existing .ppt-template from my institute. My problem now is, that the beamer template should be able to have frames with different styles for the headline within a single presentation. (do not ask why this would be necessary, I do not know)

After having a look into beamerbaseframe.sty and playing a bit with frame options, I came up with the following code

\documentclass{beamer}

\usetheme{mytheme}

\begin{document}

    \begin{frame}
        left
    \end{frame} 

    \begin{frame}[rightslide]
        right
    \end{frame} 

    \begin{frame}
        should be left again :(
    \end{frame}     

\end{document}

using beamerthememytheme.sty

\setbeamertemplate{headline}{%
    \rule{.5\paperwidth}{14mm}
}

\define@key{beamerframe}{rightslide}[true]{%
    \setbeamertemplate{headline}{\hfill\rule{.5\paperwidth}{14mm}}%
}

So the question is now: how can I revert to the default headline after the slide with the option rightslide?

enter image description here

Best Answer

You can define two different templates and reset the headline to the default style before a new frame starts.

\documentclass{beamer}
\usepackage{etoolbox}

\defbeamertemplate{headline}{mydefault}{%
  \rule{.5\paperwidth}{14mm}%
}
\defbeamertemplate{headline}{rightslide}{%
  \emph{\hfill\rule{.5\paperwidth}{14mm}}%
}

\BeforeBeginEnvironment{frame}{%
  \setbeamertemplate{headline}[mydefault]%
}

\makeatletter
\define@key{beamerframe}{rightslide}[true]{%
  \setbeamertemplate{headline}[rightslide]%
}
\makeatother

\begin{document}

\begin{frame}
  left
\end{frame} 

\begin{frame}[rightslide]
  right
\end{frame}

\begin{frame}
  is left again
\end{frame}

\end{document}

enter image description here