[Tex/LaTex] How to modify a frametitle to add a logo

beamer

Setting the frame title in beamer is quite complex. I found sources that proposed solutions that didn't work well. Basically, I want to override

\defbeamertemplate*{frametitle}{default}[1][left]

(located in beamerouterthemedefault.sty)

within my corporate sty file. I want to copy the default over and add a small minipage with my corporate logo, 2em of space, and then the frame title. I see exactly where to add the minipage but what I can't figure out is how to override the beamer template.

Apparently, there isn't a \redef function. I don't want to use \setbeamertemplate because I think #1 is actually a calculated text height for the color box. I want to override or redefine the default function with my own. One less than ideal solution is to simply import the image into my frame title but I would really like to avoid doing that for every frame.

How can I override a \defbeamertemplate* function?

Best Answer

If you look up \defbeamertemplate in the manual, you'll see that right before it there is a description of \addtobeamertemplate.

\documentclass{beamer}

\begin{document}
\addtobeamertemplate{frametitle}{\includegraphics[width=2em]{example-image-duck}%
\hspace*{2em}}{}

\begin{frame}[t]{I am a frame with a pic in the title}
But why does it have to be a duck?
\end{frame}
\end{document}

enter image description here

And if you want to vertically align the duck, you may do

\documentclass{beamer}

\begin{document}
\addtobeamertemplate{frametitle}{%
$\vcenter{\hbox{\includegraphics[width=2em]{example-image-duck}}}$%
\hspace*{2em}}{}

\begin{frame}[t]{I am a frame with a pic in the title}
But why does it have to be a duck?
\end{frame}
\end{document}

If you load tikz, you have many additional options. In particular, you could work with overlays etc. Moreover, you could load the tikzmarmots package and have a marmot in the title!

enter image description here

Related Question