I am trying to align certain images in the headline of Beamers Metropolis theme using the tikz
package. (May be there are even better approaches to do so.)
Right now, I align them using yshift
and xshift
. However, they are not perfectly aligned using this manual approach and hence look odd on high resolution presentation in which you see the offset:
\usepackage{tikz}
% headline images
\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=4.24pt, xshift = 4.2pt] at (current page.north east) {\includegraphics[height=1cm]{img/image2.png}};
\end{tikzpicture}}
\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=4.13pt, xshift = -64.8pt] at (current page.north east) {\includegraphics[height=1cm]{img/image1.png}};
\end{tikzpicture}}
The frametitle is defined as follows according to the metropolis doc:
\newlength{\metropolis@frametitle@padding}
\setlength{\metropolis@frametitle@padding}{2.2ex}
\newcommand{\metropolis@frametitlestrut@start}{
\rule{0pt}{\metropolis@frametitle@padding +%
\totalheightof{% \ifcsdef{metropolis@frametitleformat}{\metropolis@frametitleformat X}{X}% }%
}% }
\newcommand{\metropolis@frametitlestrut@end}{
\rule[-\metropolis@frametitle@padding]{0pt}{\metropolis@frametitle@padding}
}
\defbeamertemplate{frametitle}{plain}{%
\nointerlineskip%
\begin{beamercolorbox}[%
wd=\paperwidth,%
sep=0pt,%
leftskip=\metropolis@frametitle@padding,%
rightskip=\metropolis@frametitle@padding,%
]{frametitle}%
\metropolis@frametitlestrut@start\insertframetitle\metropolis@frametitlestrut@end%
\end{beamercolorbox}%
}
Possible solutions for me would be:
- Set height of images to height of frame title and do a manual horizontal alignment
- Set both heights to a fixed value (e.g. 1cm)
- A totally different approach of image placement in the frame title
MWE (Compiled with XeLaTeX):
\documentclass[unknownkeysallowed]{beamer}\usepackage[]{graphicx}\usepackage[]{color}
\usetheme[numbering = fraction]{metropolis}
\usepackage[american]{babel}
% frametitle images
\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=4.24pt, xshift = 4.2pt] at (current page.north east) {\includegraphics[height=1cm]{example-image-b}};
\end{tikzpicture}}
\addtobeamertemplate{frametitle}{}{%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,yshift=4.13pt, xshift = -44.8pt] at (current page.north east) {\includegraphics[height=1cm]{example-image-c}};
\end{tikzpicture}}
\begin{document}
% ##############################################################################
\section{Introduction}
% ------------------------------------------------------------------------------
\begin{frame}{Introduction}
test
\end{frame}
\end{document}
Best Answer
The following solution is a bit ugly, as it first measures the height of the frametitle without the logo and then uses this height for the logo, so basically all code is there two times ...
In case one would like to combine this solution with a progress bar under the frametitle: