2

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?

2
  • #1 has nothing to do text height, this is just an option to switch between left and right aligned frame titles. [left] is used as default value. If you don't need right aligned frames, you can savly overwrite the template with \setbeamertemplate{frametitle}{....} and replace the #1 in the definition with left. Sep 29, 2018 at 12:51
  • Alternatively you could copy the complete definition to your sty file and replace the name of the template, e.g. \defbeamertemplate*{frametitle}{mycompany}[1][left] and use \setbeamertemplate{frametitle}[mycompany]. This way you could even switch between left and right aligned frametitles. Sep 29, 2018 at 13:13

1 Answer 1

2

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

9
  • 1
    Nice answer, the only thing which can be improved is to add an example-image-marmot :) We should ask @Skillmon about adding such an image to duckuments :) Sep 29, 2018 at 13:16
  • 1
    @samcarter Maybe with a crystal ball. ;-)
    – user121799
    Sep 29, 2018 at 13:16
  • I did try to add text but it didn't work. When I placed text in the before option, it resulted in an error. when I placed text in the after option, it placed the text below the title bar, which makes sense. I didn't see anywhere in the definition a call to a hook for this function. I can get you the error but it appears to just be a definition issue. I got the error even with a text like "testing". Also, like with your example, the text gets placed outside of the bounding title box and it doesn't work well with multi-row frame titles. (Those were the bugs I mentioned before. ) Sep 30, 2018 at 16:51
  • @BenHolland If you append a concrete example of what you have tried to your question I will be happy to have a look at it.
    – user121799
    Sep 30, 2018 at 17:22
  • So far, I have tried: \addtobeamertemplate{frametitle}{testing before}{testing after} This resulted in "You can't use \perdepth" in horizontal mode. I tried \addtobeamertemplate{frametitle}{}{testing after} and this worked but it put the "testing after" text in a line below the title header. I tried putting this in the beamerthemeMyTheme.sty: \setbeamertemplate{frametitle}[default][left]{ \strut\insertframetitle\strut\par } And that resulted in \insertframetitle not \def'ed. So far the only thing that I managed to get working is: Oct 1, 2018 at 16:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .