TL;DR: How can I include a logo in the frame title at a fixed position with two-line titles wrapping around it?
I am creating a custom beamertheme. The frametitle has to include a logo in the top right corner and needs to be able to deal with frame titles that span two lines. Maybe I'm missing something obvious, but I can't seem to get it right.
I have used this blog entry by Matthias Vogelgesang to create most of the custom frametitle:
\setbeamertemplate{frametitle}
{%
\nointerlineskip
\begin{beamercolorbox}[sep=0.3cm,wd=\paperwidth]{frametitle}
\usebeamerfont{frametitle}%
\vbox{}\vskip-1ex%
\strut\insertframetitle\strut%
\hfill
\raisebox{-0.8mm}{\includegraphics[width=2cm,,height=0.4cm]{example-image}}
\vskip-0.8ex%
\end{beamercolorbox}
}
This would deal with longer frametitles by shifting the logo downwards:
So far I have managed to include the logo at a fixed postition using this answer by Gonzalo Medina, by removing \raisebox{-0.8mm}{\includegraphics[width=2cm,,height=0.4cm]{example-image}}
from the frametitle definition and adding this to my document:
\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=-0.05cm] at (current page.north east) {\includegraphics[width=2cm,height=0.4cm]{example-image}};
\end{tikzpicture}}
However, a longer frame title does not wrap at the image, it simply goes past it:
Is there a way to keep the logo at its position and still get longer titles to respect the logos boundaries?
MWE:
(\usetheme{Test1}
for first example, \usetheme{Test2}
for second example)
\documentclass[10pt,dvipsnames]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{filecontents}
\begin{filecontents}{beamerthemeTest1.sty}
\setbeamerfont{frametitle}{size=\large}
\setbeamercolor{frametitle}{fg=JungleGreen,bg=Dandelion!60}
\setbeamertemplate{frametitle}
{%
\nointerlineskip
\begin{beamercolorbox}[sep=0.3cm,wd=\paperwidth]{frametitle}
\usebeamerfont{frametitle}%
\vbox{}\vskip-1ex%
\strut\insertframetitle\strut%
\hfill
\raisebox{-0.8mm}{\includegraphics[width=2cm,height=0.4cm]{example-image}}
\vskip-0.8ex%
\end{beamercolorbox}
}
\end{filecontents}
\begin{filecontents}{beamerthemeTest2.sty}
\setbeamerfont{frametitle}{size=\large}
\setbeamercolor{frametitle}{fg=JungleGreen,bg=Dandelion!60}
\setbeamertemplate{frametitle}
{%
\nointerlineskip
\begin{beamercolorbox}[sep=0.3cm,wd=\paperwidth]{frametitle}
\usebeamerfont{frametitle}%
\vbox{}\vskip-1ex%
\strut\insertframetitle\strut%
\hfill
\vskip-0.8ex%
\end{beamercolorbox}
}
\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=-0.05cm] at (current page.north east) {\includegraphics[width=2cm,height=0.4cm]{example-image}};
\end{tikzpicture}}
\end{filecontents}
\usetheme{Test1}
%\usetheme{Test2}
\begin{document}
\begin{frame}{Test Frame}
Optional Content
\end{frame}
\begin{frame}{Test Frame With Really Really Really Really Really Really Long Title}
Optional Content
\end{frame}
\begin{frame}{Test Frame With Really Really Really Really Really Really Really Really Really Long Title}
Optional Content
\end{frame}
\end{document}