2

I'm having trouble aligning content top with Beamer even when I add the class option t. Ideally, I would like my content to be flushed to the same vertical height irrespective of what content I start with. But slides that start with itemize or displayed equations have some extra vertical space between the frametitle and the content. Without success, I have tried adding \vspace{-\topsep} before itemize and \vspace{-\abovedisplayskip} before align*.

In the end, I would like to use the Metropolis theme, but I suspect that the problem is unrelated to the theme.

MWE:

\documentclass[t]{beamer}
% \usetheme[sectionpage=none]{metropolis}
\begin{document}
  \begin{frame}{First frame}
    Hello, world!
  \end{frame}

\begin{frame}{Second frame} % \vspace{-\topsep} \begin{itemize} \item Hello, world! \end{itemize} \end{frame}

\begin{frame}{Third frame} % \vspace{-\abovedisplayskip} \begin{align} Hello, world! \end{align} \end{frame} \end{document}

Fredrik P
  • 1,386

2 Answers2

0

I am not sure there is a good way to achieve this. Also, I don't know which tag or environment is responsible for this (and there might well be differences for various themes, for all I know), but I think your \vspace{-...} approach might be the way to go for now.

In a case like that, I usually draw a TikZ grid on the page (or slide) in question, and adjust my values accordingly:

\documentclass[t]{beamer}
\usepackage{tikz}

\begin{document}

\newcommand\drawgrid{ \tikzset{strong lines/.style={black!25, very thin}} \begin{tikzpicture}[remember picture, overlay] \draw[style=strong lines,step=2.5mm] (current page.south west) grid (current page.north east); \end{tikzpicture}}

\begin{frame}[t]{First frame} \drawgrid

Hello, world!

\end{frame}

\begin{frame}{Second frame} \drawgrid

\vspace{-.6ex}
\begin{itemize}
      \item Hello, world!
\end{itemize}

\end{frame}

\begin{frame}{Third frame} \drawgrid

\vspace{-5.1ex}
\begin{align*}
  Hello, world!
\end{align*}

\end{frame}

\end{document}

It is, I admit, not a very elegant solution, but it should work in a pinch. I'll have to let others figure out what causes it and how to fix it “properly”.

Ingmar
  • 6,690
  • 5
  • 26
  • 47
  • The \drawgrid command shifts the frame content down, which makes the adjustments conditional on having the grid there. I suppose that one could change the color of the grid so that it invisible... – Fredrik P Mar 18 '21 at 09:23
0

\vspace{} is probably the way to go. The method to the madness (as per this answer) seems to be that displayed equations start a new paragraph (hence, vspace{-\baselineskip}) and then add a skip (hence, \vspace{-\abovedisplayskip}). As for the list, \vspace{-\topsep} is because there is space added to an assumed preceding paragraph. However, the logic behind \vspace{-\itemsep} escapes me.

\documentclass[t]{beamer}
% \usetheme[sectionpage=none]{metropolis}
\begin{document}
  \begin{frame}{First frame}
    Hello, world!
  \end{frame}

\begin{frame}{Second frame} \vspace{-\topsep}\vspace{\itemsep} \begin{itemize} \item Hello, world! \end{itemize} \end{frame}

\begin{frame}{Third frame} \vspace{-\baselineskip}\vspace{-\abovedisplayskip} \begin{align} Hello, world! \end{align} \end{frame} \end{document}

Fredrik P
  • 1,386