[Tex/LaTex] Add logo only on some frame title

beamerframe-title

I am using the solution from this question: Positioning logo in the front page as well as slides to add a logo on the top right of the title frame.

My problem is a bit more complicated:

  • I have a set of 4 logos (pdf and png)
  • some slides should not have any logo
  • some should have 1 logo
  • some should have more than 1 logo (aligned horizontally on the top right of the title bar)

I am using:

 \usetheme[height=9mm]{Rochester} 

and I am using many time the subtitles.

I have copied-and-pasted the MWE from the linked answer:

\documentclass{beamer}
\usetheme[height=9mm]{Rochester} 
\usecolortheme{beaver}
\usepackage{tikz}

\title{The title}
\institute[Inst.]{The Institute}
\date{\today}

\begin{document}


\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=2pt] at (current page.north east) {\includegraphics[height=0.8cm]{cat}};
\end{tikzpicture}}

\begin{frame}{Motivation}
Now the logo is visible
\end{frame}

\begin{frame}{Motivation}
\framesubtitle{A}
Now the logo is visible
\end{frame}

\end{document}

Best Answer

You could define the frametitle template so it puts the logos by fetching which ones from a macro that you redefine at the right points.

\documentclass{beamer}
\usetheme[height=9mm]{Rochester}
\usecolortheme{beaver}
\usepackage{tikz}

\title{The title}
\institute[Inst.]{The Institute}
\date{\today}

\def\thisframelogos{}

\newcommand{\framelogo}[1]{\def\thisframelogos{#1}}

\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=2pt] at (current page.north east) {%
    \foreach \img in \thisframelogos {%
        \hspace{.5ex}%
        \includegraphics[height=0.8cm]{\img}%
    }%
};
\end{tikzpicture}}


\begin{document}

\begin{frame}{Motivation}
No logo
\end{frame}

\framelogo{cat}

\begin{frame}{Motivation}
Now the logo is visible
\end{frame}

\framelogo{cat,cat}

\begin{frame}{Motivation}
\framesubtitle{A}
Now we have two logos
\end{frame}

\end{document}

The \thisframelogos macro stores the list of images you would like to put in the title of the next frames. The \framelogo macro just sets \thisframelogos.

When \thisframelogos is changed every frame created after the change will use its contents as the list of images to put. The images are put using a \foreach command which is defined in tikz.

To remove any logo just use \framelogo{} before your frame.

As a key for frame

To make the trick non "stateful" but applicable per-frame we can define a custom key and reset the \thisframelogos with the help of etoolbox (see this)

\documentclass{beamer}
\usetheme[height=9mm]{Rochester}
\usecolortheme{beaver}
\usepackage{tikz}
\usepackage{etoolbox}

\title{The title}
\institute[Inst.]{The Institute}
\date{\today}

\newcommand{\framelogo}[1]{\def\thisframelogos{#1}}

\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=2pt] at (current page.north east) {%
    \foreach \img in \thisframelogos {%
        \hspace{.5ex}%
        \includegraphics[height=0.8cm]{\img}%
    }%
};
\end{tikzpicture}}

\BeforeBeginEnvironment{frame}{\framelogo{}}


\makeatletter
\define@key{beamerframe}{logos}[true]{\framelogo{#1}}
\makeatother


\begin{document}

\begin{frame}{Motivation}
No logo
\end{frame}

\begin{frame}[logos=cat]{Motivation}
Now the logo is visible
\end{frame}

\begin{frame}{Motivation}
No logo again
\end{frame}

\begin{frame}[logos={cat,cat}]{Motivation}
\framesubtitle{A}
Now we have two logos
\end{frame}

\end{document}