# Insert picture in frame title in beamer

I would like to supplement frame title in beamer with a picture like this:

The picture is anchored in a fixed position (e.g. the right corner of the frame title).

I would still like to have some frames with the standard frame title. Therefore the location of "Frame title" should not jump from slide to slide.

For this I modify beamerbaselocalstructure.sty. I express the command \frametitle in the following way:

\newcommand<>\frametitle{\alt#1{\@dblarg\beamer@@frametitle}{\beamer@gobbleoptional}}
\long\def\beamer@@frametitle[#1]#2{%
\ifblank{#2}{}{%
\gdef\insertframetitle{%
\hbox{%
\begin{beamercolorbox}[wd = 0.5\paperwidth, ht = 2.25ex, dp = 1ex, center]{author in head/foot}%
frame title #2\ifnum\beamer@autobreakcount>0\relax{}\space\usebeamertemplate*{frametitle continuation}\fi\hfil
\end{beamercolorbox}%
\begin{beamercolorbox}[wd = 0.5\paperwidth, ht = 2.25ex, dp = 1ex,]{author in head/foot}%
\includegraphics[width=0.2\paperwidth]{example-image-a}

\end{beamercolorbox}%
}%
}%
\gdef\beamer@frametitle{#2}%
\gdef\beamer@shortframetitle{#1}%
}%
}


There already the first question - can I change this definition in my tex file?

Second the output is not what I intend:

As you see the picture is pressed out of the slide. Second, the frame title seems to have made a jump.

How should I modify my code? Can I provide the picture (.png/.pdf) as a parameter to \frametitle as different frames would have a different picture (including also an option of no picture)?

• In fact you don't want to insert an image in some titles. You want some slides with an image at the top right without disturbing the operation of the title (which should therefore not protrude over the image and span two lines if necessary). Did I understand your need correctly? Oct 23, 2020 at 10:07
• @PaulGaborit, that could work if the image is at the level of the title. Oct 23, 2020 at 10:13

Without any modification to the beamer code, you can use the \raisebox macro:

\documentclass{beamer}
\begin{document}
\begin{frame}
\frametitle{Title without image}
\end{frame}
\begin{frame}
\frametitle{Title \raisebox{\dimexpr \baselineskip - \totalheight}{\includegraphics[width=2cm]{example-image-a}}}
\end{frame}
\begin{frame}
\frametitle{Title \raisebox{-.5\totalheight}{\includegraphics[width=2cm]{example-image-a}}}
\end{frame}
\begin{frame}
\frametitle{Title \raisebox{\dimexpr .5ex-.5\totalheight}{\includegraphics[width=2cm]{example-image-a}}}
\end{frame}
\end{document}


• Thanks. 1) However I see that that the title is moving from slide to slide. 2) I would like to place the picture in a certain position in the frame title (that's why I employed \begin{beamercolorbox}) Oct 23, 2020 at 9:55
• I edited my answer: the (new) second slide answers 1). For 2), I don't understand your requirements. Oct 23, 2020 at 9:59
• Is it possible to anchor the picture in the right corner of the frame title? Oct 23, 2020 at 10:00