# Beamertheme-focus insert a graphic (logo) at every frame which contains a title/subtitle

I am using the Beamer theme Focus. I'd like to insert a logo in the top-right of every slide (i.e. frame) that contains a frame title (ie. not a plain slide). I have tried a lot of hacks and frustrated at the inflexibility of hand-tuning co-ordinates for placing my image at the desired location. (All that I want is to place the image at the top-right).

For now, we may assume that I'd like to insert a generic cat picture from the www. I'd relly appreciate a solution for this problem.

Here's an MWE for starters

\documentclass{beamer}
\usetheme{focus}

\title{Focus: \\ A Minimalist Beamer Theme}
\subtitle{Subtitle}
\author{Author 1\texorpdfstring{\\}{,} Author 2}
\titlegraphic{\includegraphics[scale=1.25]{focuslogo.pdf}}
\date{dd mm yyyy}

\begin{document}
\begin{frame}
\maketitle
\end{frame}

% Use starred version (e.g. \section*{Section name})
% to disable (sub)section page.
\section{Section 1}
\subsection{Subsection 1.1}
\begin{frame}{Simple frame}
This is a simple frame.
\end{frame}

\begin{frame}[plain]{Plain frame}
This is a frame with plain style and it is numbered.
\end{frame}

\subsection{Subsection 1.2}
\begin{frame}[t]
This frame has an empty title and is aligned to top.
\end{frame}

This frame is not numbered and is citing reference \cite{knuth74}.
\end{frame}

\begin{frame}{Typesetting and Math}
The packages \texttt{inputenc} and \texttt{FiraSans}\footnote{\url{https://fonts.google.com/specimen/Fira+Sans}}\textsuperscript{,}\footnote{\url{http://mozilla.github.io/Fira/}} are used to properly set the main fonts.
\vfill
This theme provides styling commands to typeset \emph{emphasized}, \alert{alerted}, \textbf{bold}, \textcolor{example}{example text}, \dots
\vfill
\texttt{FiraSans} also provides support for mathematical symbols:
\begin{equation*}
e^{i\pi} + 1 = 0.
\end{equation*}
\end{frame}
\end{document}

• Would you be happy with a solution that requires a second compilation run? Jul 15 '20 at 22:50
• @TobiBS Yes, As long as latexmk works (which automatically runs however many times as needed till a non-changing PDF is obtained), I am cool. Jul 15 '20 at 22:51

So the task is to have a logo on every frame where the frametitle is actually typeset. Let's have a look into the theme what it does and where it defines it.

Normally frametitles are defined in the outer theme, therefore let's have a look into beamerouterthemefocus.sty, which defines two named templates for the frametitle:

1. \defbeamertemplate*{frametitle}{focus}{%
2. \defbeamertemplate*{frametitle}{plain}{%

Later in the same file, we can see that focus is used for every frame that is not the first frame or where plain was set:

\BeforeBeginEnvironment{frame}{%
\setbeamertemplate{background canvas}[focus]%
\setbeamertemplate{frametitle}[focus]%


and

\define@key{beamerframe}{plain}[true]{%
\setbeamertemplate{background canvas}[focusplain]%
\setbeamertemplate{frametitle}[plain]%


So just setting the frametitle through \setbeamertemplate or using \addtobeamertemplate will do no good, as on the next frame, frametitle will be redefined to focus. But \defbeamertemplate*{frametitle}{focus} won't work either. So how can we overcome this?

Well there is a trick explained in How to redefine a beamer template which basically is to let beamer think, focus is not yet defined for frametitle.

The rest is easy, we can make use of beamer with its feature to reference the current page and the only drawback is that you have to compile multiple times. Our final result of the lines to add is hence:

\expandafter\let\csname beamer@@tmpop@frametitle@focus\endcsname\relax
\defbeamertemplate*{frametitle}{focus}{%
% If not title page.
\vspace{-1pt}%
\begin{beamercolorbox}[wd=\paperwidth,leftskip=0.55cm,rightskip=0.55cm,sep=0.2cm]{frametitle}%
\strut\insertframetitle\strut%
\end{beamercolorbox}%
\fi%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east] at (current page.north east){\includegraphics[width=1.6cm]{example-image-16x9}};
\end{tikzpicture}
}


Just add this before the \begin{document} and you will get:

• focus is really odd in its resetting of the templates at every frame... I had a look on how to avoid all that messed \BeforeBeginEnvironment but my beamer skills are not good enough Jul 17 '20 at 9:04
• @capitalaslash well there are multiple ways to achieve certain behaviors, besides the one used by focus, you can use pagestyles, as in tex.stackexchange.com/questions/317938/… but this has caveats, e.g. when you try to use it for the frametitle: tex.stackexchange.com/questions/552234/… So it seems the developers had reasons to use this approach. Jul 17 '20 at 9:22
• I understand that is required for the dynamic footer that changes in every page, but the frametitle is static and behaviorally identical to the standard theme. This approach defies all standard beamer tools such as \addtobeamertemplate and \defbeamertemplate` and in my opinion it makes the theme unusable. Jul 17 '20 at 9:30
• @TobiBS thanks a lot for the nice answer!. Accepted, upvoted and bounty awarded. Jul 24 '20 at 11:09
• @Krishna thanks for your appreciation! Jul 24 '20 at 11:41