Design a custom Beamer theme from scratch

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:

  1. beamercolorthemetexsx.sty
  2. beamerinnerthemetexsx.sty
  3. beamerouterthemetexsx.sty
  4. beamerthemetexsx.sty
  5. 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{[email protected]}}

\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:

enter image description here

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{[email protected]}}

\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:

enter image description here

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.


Using Claudio's answer as a starting point, I developed two themes which I made available here, one based on the PowerPoint Median theme and one based on the Powerdot KlopeSpring theme. There may be more to come.

In addition to the techniques Claudio demonstrated, I used the textpos package to do absolute positioning of text on the page.

In order to achieve different frame backgrounds on section pages and plain frames, I used something like

\newcommand{\sectionframe}{{
    \setbeamertemplate{background}{
      % draw the different background
    }
    \setbeamertemplate{headline}{}
    \frame{\sectionpage}
}}

Note the double curly brackets; the inner pair puts everything in a group and thus keeping the template changes local.

Here are some images:

sample slides