Is there a way to easily add an image to a section slide in the Metropolis theme for beamer?

Basically, I have this using \section{Selection Bias}:

enter image description here

And want this:

enter image description here

I found a related answer here, but it seems like there might be a more efficient way to do this without renewing the command every time, and I'd rather not rebuild the title part because I like having the indicator bar, etc.

  • Please, can you add your complete code? This way it's easier to help you. – Sebastiano Dec 2 '17 at 21:07
  • Yes, sorry @Sebastiano. The code in the answer is sufficient to run, but next time I'll include from the start. – atkat12 Dec 3 '17 at 0:08
up vote 5 down vote accepted

If you don't like the renewcommand, you could pass the image name as optional argument to the section page template.

\documentclass{beamer}
\usetheme{metropolis}

%%% Section page template with picture

\makeatletter
\defbeamertemplate*{section page}{mytheme}[1][]{
  \centering
  \begin{minipage}{22em}
    \raggedright
    \usebeamercolor[fg]{section title}
    \usebeamerfont{section title}
    \insertsectionhead\\[-1ex]
    \usebeamertemplate*{progress bar in section page}
    \par
    \ifx\insertsubsectionhead\@empty\else%
      \usebeamercolor[fg]{subsection title}%
      \usebeamerfont{subsection title}%
      \insertsubsectionhead
    \fi
    \vskip0.5cm
    \ifstrempty{#1}{}{%
        \includegraphics[width=.4\textwidth]{#1}%
    }
  \end{minipage}
  \par
  \vspace{\baselineskip}
}
\makeatother

%%% Define a command to include picture in section, 
%%% make section, and revert to old template

\newcommand{\sectionpic}[2]{
   \setbeamertemplate{section page}[mytheme][#2]
   \section{#1}
   \setbeamertemplate{section page}[mytheme]
}

%%% Document

\begin{document}

\section{normal}    
\begin{frame}
    abc
\end{frame} 

\sectionpic{image}{example-image}
\begin{frame}
    abc
\end{frame}

\end{document}
  • Thank you @samcarter! Works great. I just added a short command, sectionpic, to insert a photo section and revert the template in a single command, so you don't have to manually do this every time. – atkat12 Dec 3 '17 at 0:06

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.