1

I'm using the metropolis theme in Beamer and I would like to center (in the space) a house image in the frametitle. How could I do that? Below there is a MWE.

Thanks a lot.

enter image description here

\documentclass[t,aspectratio=169]{beamer}
\usetheme[progressbar=frametitle,block=fill]{metropolis}

\setbeamertemplate{frame numbering}[fraction]
\useoutertheme{metropolis}
\useinnertheme{metropolis}
\usefonttheme{metropolis}
\usecolortheme{owl}
\usepackage{amsmath,amsfonts,amscd,bezier, amssymb, ifthen,amsthm}
\usepackage{graphics}
\usepackage{xcolor}

\usepackage[T1]{fontenc}
\usepackage{float}
\usepackage{pgfplots} % it is required for the legend
\usepackage{mathtools}
\usepackage{changepage}
\usepackage[most]{tcolorbox}




\title{XXXXXXX}
\subtitle{xxxxxxx}
\author{}
\institute{yyyyy}
\date{}

\everymath{\displaystyle}

\setbeamercolor*{item}{fg=yellow}

\setbeamersize{text margin left=3mm,text margin right=1mm}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newenvironment<>{varblock}[2][.9\textwidth]{%
    \setlength{\textwidth}{#1}
    \begin{actionenv}#3%
        \def\insertblocktitle{#2}%
        \par%
        \usebeamertemplate{block begin}}
    {\par%
        \usebeamertemplate{block end}%
\end{actionenv}}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\metroset{background=dark}
\metroset{block=fill}

%\setcounter{page}{0}       
        \begin{frame}
        
        \titlepage
        \thispagestyle{empty}
    \end{frame}

\begin{frame}{\color{red}{Exercises:} {\includegraphics[scale=0.05]{house}}}
\begin{alertblock}{Exercise 1:}
blabla bla
\end{alertblock}

%https://br.depositphotos.com/2467738/stock-illustration-vector-illustration-of-house.html

\begin{alertblock}{Exercise 2:}
blablabla. 
\end{alertblock}
\end{frame}

\end{document}

3 Answers 3

1

You could use the adjustbox package to vertically centre the image:

\documentclass[t,aspectratio=169]{beamer}
\usetheme[progressbar=frametitle,background=dark]{moloch}% modern fork of the metropolis theme
\setbeamertemplate{page number in head/foot}[totalframenumber]

\usecolortheme{owl}
\usepackage{
%amsmath,amsfonts,amscd,
bezier, 
%amssymb, 
ifthen,
%amsthm
}
%\usepackage{graphics}
%\usepackage{xcolor}

\usepackage[T1]{fontenc}
%\usepackage{float}
\usepackage{pgfplots} % it is required for the legend
\usepackage{mathtools}
\usepackage{changepage}
\usepackage[most]{tcolorbox}
\usepackage[export]{adjustbox}




\title{XXXXXXX}
\subtitle{xxxxxxx}
\author{}
\institute{yyyyy}
\date{}

\everymath{\displaystyle}

\setbeamercolor*{item}{fg=yellow}

\setbeamersize{text margin left=3mm,text margin right=1mm}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newenvironment<>{varblock}[2][.9\textwidth]{%
    \setlength{\textwidth}{#1}
    \begin{actionenv}#3%
        \def\insertblocktitle{#2}%
        \par%
        \usebeamertemplate{block begin}}
    {\par%
        \usebeamertemplate{block end}%
\end{actionenv}}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

%\setcounter{page}{0}       
        \begin{frame}
        
        \titlepage
        \thispagestyle{empty}
    \end{frame}

\begin{frame}{\color{red}{Exercises:} {\includegraphics[height=1.5cm,valign=c]{example-image-duck}}}
\begin{alertblock}{Exercise 1:}
blabla bla
\end{alertblock}

\begin{alertblock}{Exercise 2:}
blablabla. 
\end{alertblock}
\end{frame}

\end{document}

enter image description here

1

If you want to center it horizontally, you can use

\begin{frame}{\rlap{\color{red}{Exercises:}}%
  \hfill\includegraphics[height=\ht\strutbox]{example-image}\hfill
  \llap{right}}

The \rlap and \llap cause the text to overlap the \hfills. The text on the right is there mostly to show where the end of the line is located.

If you want to center it vertically relative to the text, you can use

\begin{frame}{{\color{red}{Exercises:}} \raisebox{\dimexpr 0.5\ht\strutbox-0.5\dp\strutbox-0.5\height}%
  {\includegraphics[height=40pt]{example-image}}}

Note that the \beamer@frametitlebox expands to fit the image.

1
  • Thank you, this is working but the figure was centered on the page and I would like the figure to be close to Exercises and bigger than your solution.
    – Moura
    May 6, 2021 at 18:36
1

You can add \centering before \insertframetitle. In what follows, we define and install such a template.

Add the following definition in the preamble of your document:

\makeatletter
\defbeamertemplate*{frametitle}{centered}{%
  \nointerlineskip%
  \begin{beamercolorbox}[%
      wd=\paperwidth,%
      sep=0pt,%
      leftskip=\metropolis@frametitle@padding,%
      rightskip=\metropolis@frametitle@padding,%
    ]{frametitle}%
    \metropolis@frametitlestrut@start%
  \centering\insertframetitle%
  \nolinebreak%
  \metropolis@frametitlestrut@end%
  \end{beamercolorbox}%
}
\makeatother
1
  • I really appreciated your answer. But unfortunately I didn't ask a good question. My English is so bad. I would like to move the house´s image to down like as Exercises´s word at the Frametitle as is the word Exercise, not centering at the Frametitle.
    – Moura
    Jun 7, 2021 at 15:18

You must log in to answer this question.

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