Is it possible to change beamer theme mid document or do you have to make two pdfs and stick them together?
[Tex/LaTex] Change beamer theme mid document
beamer
Related Solutions
Build your own theme: no one forces you to exploit predefined inner, outer, color and font themes. Look at this theme: is it instantly recognisable as Beamer ?
But, let's have a practical example: it is one hour-built theme, thus take it just for demonstration. Lot of improvements can be done. The reference is one of your pictures.
We call this new theme texsx
mainly due to the fact that I don't have much fantasy with names. So in a directory we create the following files:
beamercolorthemetexsx.sty
beamerinnerthemetexsx.sty
beamerouterthemetexsx.sty
beamerthemetexsx.sty
texsx-example.tex
To build the theme we might exploit TikZ: very likely you can avoid it, but the question has the magic tag, so I felt almost obligated (even if the true reason is: with TikZ was faster ;)
).
So we keep beamerthemetexsx.sty
very simple:
\mode<presentation>
% Requirement
\RequirePackage{tikz}
% Settings
\useinnertheme{texsx}
\useoutertheme{texsx}
\usecolortheme{texsx}
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{blocks}[rounded][shadow=true]
\mode<all>
we load the themes, remove the navigation symbols and define blocks aspect.
Now, let's start define the title page in the inner
theme. As we need to test what we're doing, at first is is better to set up the example document:
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\title{There Is No Largest Prime Number}
\date[ISPN ’80]{27th International Symposium of Prime Numbers}
\author[Euclid]{Euclid of Alexandria \texttt{euclid@alexandria.edu}}
\usetheme{texsx}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\end{document}
Nothing is strange or difficult till now. Time to build the titlepage; I would proceed as follows:
- exploit the
background
template to set the titlepage background - define a
title page
template in which the title, the author and the date are actually set.
The operations described are translated in beamerinnerthemetexsx.sty
in the following way:
\mode<presentation>
\setbeamertemplate{background}{
\begin{tikzpicture}
\useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
\fill[color=brown] (0,2) rectangle (\the\paperwidth,\the\paperheight);
\fill[color=orange] (0,0) rectangle(2.95,1.9);
\fill[color=blue!50!cyan!80] (3.05,0) rectangle(\the\paperwidth,1.9);
\ifnum\thepage>1\relax%
\fill[white,opacity=1] (0,0) rectangle(\the\paperwidth,\the\paperheight);
\fi
\end{tikzpicture}
}
% Title page
\defbeamertemplate*{title page}{texsx}[1][]
{
\vskip6cm%
\begin{beamercolorbox}[wd=12cm,leftskip=3cm,sep=8pt,#1]{title page header}
\usebeamerfont{title}\inserttitle\par%
\end{beamercolorbox}%
\vskip0.75cm%
\begin{beamercolorbox}[wd=12cm,leftskip=3cm,#1]{author}
\usebeamerfont{author}\insertauthor%
\end{beamercolorbox}
\vskip0.2cm%
\begin{beamercolorbox}[wd=12cm,leftskip=3cm,#1]{date}
\usebeamerfont{author}\insertdate%
\end{beamercolorbox}
\vfill
}
\mode
<all>
It is important to notice that we define ourself the bounding box through \useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
then, thanks to the test on the page number, we apply the background on the title page only.
In the title page
template then we actually put the elements mentioned above. We characterize their color aspect passing to beamercolorboxes
title page header
, author
, date
so we need these definitions. Let's add them to the beamercolorthemetexsx.sty
:
\mode<presentation>
% Settings
\setbeamercolor*{title page header}{fg=white}
\setbeamercolor*{author}{fg=white}
\setbeamercolor*{date}{fg=white}
\mode
<all>
Now, if we compile our example we get:
Cool!
Let's going on defining the aspect of the frame title. This is done with a template called frametitle
in the beamerouterthemetexsx.sty
, which looks like:
\mode<presentation>
% Frame title
\defbeamertemplate*{frametitle}{texsx}[1][]
{
\vskip1cm%
\begin{beamercolorbox}[wd=\paperwidth,ht=1.2cm]{frametitle}
\begin{tikzpicture}
\useasboundingbox[fill=white](0,0) rectangle(\the\paperwidth,1.2);
\fill[orange] (0,0) rectangle(2.95,1.2);
\fill[blue!50!cyan!80] (3.05,0) rectangle(\the\paperwidth,1.2);
\ifx\insertframesubtitle\@empty%
{\node[anchor=west, white,font=\large] at (3.2,0.61){\insertframetitle};}
\else%
{\node[anchor= west, white,font=\large] at (3.2,0.81){\insertframetitle};%
\node[anchor= west, white,font=\small] at (3.2,0.41){\insertframesubtitle};}%
\fi
\end{tikzpicture}
\end{beamercolorbox}
}
\mode<all>
Basically, we exploit the same concept of the titlepage to draw some boxes; then we check whether the subtitle is present: accordingly we set the position of title and subtitle or we set only the frame title with TikZ nodes.
We need again tests to verify our idea. So let's add something on our example:
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\title{There Is No Largest Prime Number}
\date[ISPN ’80]{27th International Symposium of Prime Numbers}
\author[Euclid]{Euclid of Alexandria \texttt{euclid@alexandria.edu}}
\usetheme{texsx}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}
\frametitle{There Is No Largest Prime Number}
\framesubtitle{The proof uses \textit{reductio ad absurdum}.}
\begin{theorem}
There is no largest prime number. \end{theorem}
\begin{enumerate}
\item<1-| alert@1> Suppose $p$ were the largest prime number.
\item<2-> Let $q$ be the product of the first $p$ numbers.
\item<3-> Then $q+1$ is not divisible by any of them.
\item<1-> But $q + 1$ is greater than $1$, thus divisible by some prime
number not in the first $p$ numbers.
\end{enumerate}
\end{frame}
\begin{frame}{A longer title}
\begin{itemize}
\item one
\item two
\end{itemize}
\end{frame}
\end{document}
As we also have lists, we have to define their aspect and color. So we need to add:
\setbeamercolor*{item}{fg=orange}
in our beamercolorthemetexsx.sty
and:
% Items
\setbeamertemplate{items}[square]
\setbeamertemplate{sections/subsections in toc}[square]
in beamerinnerthemetexsx.sty
. It is not mandatory to put the latter definitions in the inner theme, but I followed the Beamer style.
It seems to me we can compile our document; the result is:
Ok, I agree: the colors are not the ones in the reference picture and the subtitle is not perfectly aligned with the title (this is due to the font size difference), but the new theme is here.
Here's the definition of the footline used by CambridgeUS (from the file beamerouterthemeinfolines.sty
):
\defbeamertemplate*{footline}{infolines theme}
{
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
\usebeamerfont{author in head/foot}\insertshortauthor\expandafter\beamer@ifempty\expandafter{\beamer@shortinstitute}{}{~~(\insertshortinstitute)}
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
\usebeamerfont{title in head/foot}\insertshorttitle
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,right]{date in head/foot}%
\usebeamerfont{date in head/foot}\insertshortdate{}\hspace*{2em}
\insertframenumber{} / \inserttotalframenumber\hspace*{2ex}
\end{beamercolorbox}}%
\vskip0pt%
}
Clearly, the /
you want to replace is on the \insertframenumber{} / \inserttotalframenumber\hspace*{2ex}
row.
As for the titlepage, you can use \begin{frame}[plain]
to get an empty titlepage.
Here's an MWE with a redefinition of the footline:
\documentclass{beamer}
\mode<presentation> {
\usetheme{CambridgeUS}
\usecolortheme{lily}
\useinnertheme{circles} % rectangles, circles, inmargin, rounded
}
\setbeamertemplate{blocks}[rounded][shadow=true]
\makeatletter
\setbeamertemplate{footline}%{infolines theme}
{
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
\usebeamerfont{author in head/foot}\insertshortauthor\expandafter\beamer@ifempty\expandafter{\beamer@shortinstitute}{}{~~(\insertshortinstitute)}
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
\usebeamerfont{title in head/foot}\insertshorttitle
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,right]{date in head/foot}%
\usebeamerfont{date in head/foot}\insertshortdate{}\hspace*{2em}
\insertframenumber{} -- \inserttotalframenumber\hspace*{2ex}
\end{beamercolorbox}}%
\vskip0pt%
}
\makeatother
% gets rid of navigation symbols
\setbeamertemplate{navigation symbols}{}
% add figures numbering
\setbeamertemplate{caption}[numbered]
\setcounter{tocdepth}{1} % in the table of contents
\setcounter{secnumdepth}{2} % with a number
\title[SCI Communication]{Serial Communication Interface Evaluation} % The short title appears at the bottom of every slide, the full title is only on the title page
\subtitle{EE-491(a): Project in Electrical Energy Systems}
\author{Antoine Giraldi} % Your name
\institute[EPFL] % Your institution as it will appear on the bottom of every slide, may be shorthand to save space
{Power Electronics Laboratory, EPFL
% \inst{1}%
% EPFL %\\ % Your institution for the title page
% \and
% \inst{2}%
% Power Electronics Laboratory
%\bigskip
%\textit{Power Electronics Laboratory} % Your email address
}
\date{\today} % Date, can be changed to a custom date
\begin{document}
%------------------------------------------------
\begin{frame}[plain]
\titlepage % Print the title page as the first slide
\end{frame}
\section[Technical Approach]{Technical Approach}
%------------------------------------------------
\begin{frame}
\frametitle{Simulink implementation}
\end{frame}
\end{document}
And the result:
You can change \setbeamertemplate{blocks}[rounded][shadow=true]
to change the block appearance and use \setbeamersize{text margin left=0pt,text margin right=0pt}
to change the text margin.
Let me know if you have any questions!
Best Answer
beamer themes (main themes as well as color, font, inner and outer themes) may not be switched mid-document. However, it is possibe (though perhaps not always desirable) to change beamer's internal settings in accordance with a desired new theme. In the following example, I mimic a switch from the default settings to that of the "orchid" color theme.