2

I'm dealing with a presentation, and I need to put the logo at the top right of the header. This a MWE from which my code is inspired:

\documentclass{beamer}

\usetheme{metropolis}

\makeatletter
\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
  \raisebox{-0.6ex}{\includegraphics[height=3ex,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}

I would like to know how I could control the horizontal position of the logo in the header. I mean, \raisebox allows to control the vertical position, so which command should I use to achieve horizontal control? I need to move slightly on the left the logo, because my actual code places the logo too much close to the right edge.

1
  • Please see the updated answer. Jun 23, 2021 at 13:47

1 Answer 1

2

UPDATED

In your MWE replace \hfill with a (negative) horizontal space.

In the code set \rightgap to move the logo to the left side of the frame.

w1

\documentclass{beamer}      

\newlength{\rightgap}
\setlength{\rightgap}{30pt} % adjust to move the logo to the left<<<<<<<

\usetheme{metropolis}

\makeatletter
\setbeamertemplate{frametitle}{%
    \nointerlineskip%
    \begin{beamercolorbox}[%
        wd=\paperwidth,%
        sep=0pt,%
        leftskip=\metropolis@frametitle@padding,%
%       rightskip=\metropolis@frametitle@padding,%
        ]{frametitle}%
        \metropolis@frametitlestrut@start%
        \parbox{0.85\paperwidth}{\insertframetitle}% changed <<<<<
        \nolinebreak%
        \metropolis@frametitlestrut@end%
%       \hfill
        \hspace*{-\rightgap} % move the logo to the left<<<<<<<     
        \raisebox{-0.8ex}{\includegraphics[height=3ex,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}

    \begin{frame}{My frame long long long long long long long 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}
1
  • Hi @SimonDispa, thank you for your contribution. Something weird happens with the code, I've tried your solution which partly works, but the logo position is not constant throughout the frames, indeed the logo shifts, while it is supposed to be fixed in the same position.
    – Catarella
    Jun 23, 2021 at 8:15

You must log in to answer this question.

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