5

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: functioning frametitle with logo frametitle with logo moved left frametitle with logo shifted 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: functioning frametitle with logo frametitle with text behind logo frametitle with two lines

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}
3

Does adding rightskip=2cm to the option list of beamercolorbox in your beamerThemeTest2.sty fulfill your expectations?

Line 31 of your MWE thus looks like this:

\begin{beamercolorbox}[sep=0.3cm,rightskip=2cm,wd=\paperwidth]{frametitle}

That way, the text stays out of the image. I have not checked whether the vertical margins remain the same, though.

3

In your second theme, you could place the title in some element of which you can control the width, e.g. a \parbox or a minipage

(the .8\textwidth are just a quick guess, you might have to fine tune it a bit)

\documentclass[10pt,dvipsnames]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}

\usepackage{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%
            \parbox{.8\textwidth}{\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{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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.