0

In beamer, when I start a slide with equation, then when the slide is full, the slide starts way below the slide title.

enter image description here

When I start a slide with text, then when the slide is full, it starts very minimally below the slide title. I like this to happen even for equation.

enter image description here

Entire source code for this example:

% Preview source code
%% LyX 2.3.3 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english]{beamer}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
% this default might be overridden by plain title style
\newcommand\makebeamertitle{\frame{\maketitle}}%
% (ERT) argument for the TOC
\AtBeginDocument{%
  \let\origtableofcontents=\tableofcontents
  \def\tableofcontents{\@ifnextchar[{\origtableofcontents}{\gobbletableofcontents}}
  \def\gobbletableofcontents#1{\origtableofcontents}
}

\makeatother

\usepackage{babel}
\begin{document}
\begin{frame}{A}

\[
1
\]

\begin{itemize}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\end{itemize}
\end{frame}

\begin{frame}{B}

1
\begin{itemize}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\end{itemize}
\end{frame}
\end{document}

This question may sound similar with Weird gap within box if I type equation instead of text but that question was the gap within a box.

user42459
  • 207

1 Answers1

3

LaTeX, and its documentclass authors have added default spacing for pretty much every thing. The default spacing around equations is different from the space around normal text. Whenever you come across a spacing issue like this, the best bet is to search (I use google) on how to undo that particular space. In your case we need to undo/remove two kinds of space by performing these two steps:

(1) Remove extra vertical space around equations: Adding the following lines to the preamble should remove extra vertical spacing above and below the equations.

\makeatletter
\g@addto@macro\normalsize{%
  \setlength\abovedisplayskip{-8pt}
  \setlength\belowdisplayskip{-8pt}
  \setlength\abovedisplayshortskip{-8pt}
  \setlength\belowdisplayshortskip{-8pt}
}
\makeatother

Note: the amount chosen here -8pt is dependent on font size. So if you change font size, then you will have to update this too. To get further explanation on this, please check this link on removing vertical space around equations.

(2) Flush the equation to left margin of text: For this, you need to write all your equation in aligned environment, like this:

$\begin{aligned}
1
\end{aligned}$

and not like this:

\[
1
\]

To get further explanation on this, please check this link on left aligning equations

While debugging if you want to visualize spaces, there is a great lualatex package called lua-visual-debug available here. Following is the entire code to visualize spaces with lualatex. Note: the above solution works for all engines (not just lualatex), and the following code is just for further education in case you want to visualize spaces, and see things for yourself.

Run command: >> lualatex <filename>.tex from command line or check if you can select lualatex as your latex engine in LyX. First run it as it is, then run it by commenting/deleting the lines that I suggest to add and compare the pdf outputs. To understand the markers, check the documentation of lua-visual-debug

% Edited LyX code only for visualization of spaces with lua-visual-debug.

\documentclass[english]{beamer}
%\usepackage[T1]{fontenc}
%\usepackage[latin9]{inputenc}
\usepackage{lua-visual-debug}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

\makeatletter
\g@addto@macro\normalsize{%
  \setlength\abovedisplayskip{-8pt}
  \setlength\belowdisplayskip{-8pt}
  \setlength\abovedisplayshortskip{-8pt}
  \setlength\belowdisplayshortskip{-8pt}
}
\makeatother



\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
% this default might be overridden by plain title style
\newcommand\makebeamertitle{\frame{\maketitle}}%
% (ERT) argument for the TOC
\AtBeginDocument{%
  \let\origtableofcontents=\tableofcontents
  \def\tableofcontents{\@ifnextchar[{\origtableofcontents}{\gobbletableofcontents}}
  \def\gobbletableofcontents#1{\origtableofcontents}
}

\makeatother

\usepackage{babel}
\begin{document}
\begin{frame}{A}

$\begin{aligned}
1
\end{aligned}$

\begin{itemize}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\end{itemize}
\end{frame}

\begin{frame}{B}

1
\begin{itemize}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\item {\Huge{}dd}{\Huge\par}
\end{itemize}
\end{frame}
\end{document}

codepoet
  • 1,316
  • Thank you. But this does not seem to push the first equation to right below the slide title. It seems it reduces the gap between equation other equation, and equation and text. – user42459 Apr 09 '20 at 15:43
  • @user42459 Here we go, I updated the answer to remove extra horizontal space too. Please check, and if it works then mark this answer as accepted by clicking on the check mark ✓. – codepoet Apr 09 '20 at 23:58