[Tex/LaTex] Logo in a frametitle, metropolis theme

beamerbeamer-metropolispresentationsthemes

This is the additional question, continuation of my problem given here: How to change the frametitle / footline height in metropolis theme?

I hope that the new post is better to solve a related problem from the comment or auto-ansewring my old question. My explanation is too big here. Please correct me if such method is not accepted here.

Let's start with my MWE. The footline was nicely created for my by @samcarter. Thanks once more.

\documentclass{beamer}

\usetheme[numbering=none,block=fill]{metropolis}

\setbeamerfont{frametitle}{size=\normalsize,series=\normalfont\bfseries}
\setbeamerfont{page number in head/foot}{size=\normalsize,series=\normalfont\bfseries}

\setbeamercolor{footline}{fg=black!2, bg=mDarkTeal}
\setbeamertemplate{frame footer}{My footline}

\makeatletter
\setlength{\metropolis@frametitle@padding}{0.7ex}% <- default 2.2 ex

\setbeamertemplate{footline}{%
    \begin{beamercolorbox}[wd=\textwidth, sep=0.7ex]{footline}% <- default 3ex
        \usebeamerfont{page number in head/foot}%
        \usebeamertemplate*{frame footer}
        \hfill%
        \usebeamertemplate*{frame numbering}
    \end{beamercolorbox}%
}
\makeatother

\begin{document}

\begin{frame}{My frame title}
 \begin{block}{Some itemize}
  \begin{itemize}
   \item \alert{Item 1}
   \item Item 2
  \end{itemize}
 \end{block}
 \begin{block}{Some maths}
 \[\sum_{n=1}^{\infty}\frac{1}{n^2}=\frac{\pi^2}{6}=\zeta(2)\]
\end{block}
\end{frame}

\end{document}

The Dropbox link to a logo image is here: https://www.dropbox.com/s/z37855vt0f84okd/BM.png?dl=0

How do things look like?

enter image description here

I achieved it by a poorman trick with adding some code to the beamerouterthememetropolis.sty file. Below the appropriate fragment (starting in 90-th line of a file):

\defbeamertemplate{frametitle}{plain}{%
  \nointerlineskip%
  \begin{beamercolorbox}[%
      wd=\paperwidth,%
      sep=0pt,%
      leftskip=\metropolis@frametitle@padding,%
      rightskip=\metropolis@frametitle@padding,%
    ]{frametitle}%
  \metropolis@frametitlestrut@start%
  \insertframetitle%
  \nolinebreak%
  \metropolis@frametitlestrut@end%
  \hfill
  \includegraphics[height=0.27cm,keepaspectratio]{BM}
  \end{beamercolorbox}%
}

Now, how to make this trick work by modifying my MWE only, not by modifying a theme file? I have tried with \addtobeamertemplate command, with no effect.

Few additional questions.

  1. How to adjust the logo image height automatically to the actual font height, not by putting the direct size, but by some command? Look at another screenshot.

enter image description here

  1. While the text of a frame title is more or less well vertically centered in a headline, this is not the case in the footline. Is it possible to correct it?

  2. Are R:250, G:250, B:250 correct values for a black!2 color? As far as I know black!2 means 2% of black and 98% of white, so the number 0 should be transformed to 0*0.02+255*0.98=249.9, that's why my 250 number. I needed it to make a proper color of my logo.

Many thanks for all people who read this long post up to the end.

Best Answer

Instead of hacking the .sty file (which causes also a problem with the licence), you can add the frame title definition to your .tex file.

To automatically scale it, choose units relative to the font size, e.g. ex.

\documentclass{beamer}

\usetheme[numbering=none,block=fill]{metropolis}

%\setbeamerfont{frametitle}{size=\normalsize,series=\normalfont\bfseries}
\setbeamerfont{frametitle}{size=\Huge,series=\normalfont\bfseries}
\setbeamerfont{page number in head/foot}{size=\normalsize,series=\normalfont\bfseries}

\setbeamercolor{footline}{fg=black!2, bg=mDarkTeal}
\setbeamertemplate{frame footer}{My footline}

\makeatletter
\setlength{\metropolis@frametitle@padding}{0.7ex}% <- default 2.2 ex

\setbeamertemplate{footline}{%
    \begin{beamercolorbox}[wd=\textwidth, sep=0.7ex]{footline}% <- default 3ex
        \usebeamerfont{page number in head/foot}%
        \usebeamertemplate*{frame footer}
        \hfill%
        \usebeamertemplate*{frame numbering}
    \end{beamercolorbox}%
}

\setbeamertemplate{frametitle}{%
  \nointerlineskip%
  \begin{beamercolorbox}[%
      wd=\paperwidth,%
      sep=0pt,%
      leftskip=\metropolis@frametitle@padding,%
      rightskip=\metropolis@frametitle@padding,%
    ]{frametitle}%
  \metropolis@frametitlestrut@start%
  \insertframetitle%
  \nolinebreak%
  \metropolis@frametitlestrut@end%
  \hfill
  \includegraphics[height=1.5ex,keepaspectratio]{example-image-duck}
  \end{beamercolorbox}%
}


\makeatother

\begin{document}

\begin{frame}{My frame title}
 \begin{block}{Some itemize}
  \begin{itemize}
   \item \alert{Item 1}
   \item Item 2
  \end{itemize}
 \end{block}
 \begin{block}{Some maths}
 \[\sum_{n=1}^{\infty}\frac{1}{n^2}=\frac{\pi^2}{6}=\zeta(2)\]
\end{block}
\end{frame}

\end{document}