1

On Lyx, if I type an equation like this

enter image description here

then I get this on pdf

enter image description here

I mean, there is a huge gap within the box above the equation.

But if I type a non-equation text like this

enter image description here

then it's normal on pdf.

enter image description here

How can I remove that gap when I type equation within the box?

And here is the tex code that I used to generate it.

\documentclass[english]{beamer}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{calc}
\usepackage{amsmath}

\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}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\setbeamerfont{footline}{series=\bfseries}
\setbeamertemplate{navigation symbols}{% 
\insertslidenavigationsymbol \insertframenavigationsymbol 
\insertsubsectionnavigationsymbol \insertsectionnavigationsymbol 
\insertdocnavigationsymbol \insertbackfindforwardnavigationsymbol \hspace{1em}% 
\usebeamerfont{footline} \insertframenumber/\inserttotalframenumber% 
}

\makeatother

\usepackage{babel}
\begin{document}
\begin{frame}[t]{Title}
\begin{center}
{\small{}}%
\fbox{\begin{minipage}[t]{0.8\columnwidth}%
{\small{}
\begin{align*}
 & equation
\end{align*}
}%
\end{minipage}}{\small\par}
\par\end{center}
\begin{itemize}
\item Content
\item Content
\end{itemize}
\end{frame}

\begin{frame}[t]{Title}
\begin{center}
{\small{}}%
\fbox{\begin{minipage}[t]{0.8\columnwidth}%
\begin{center}
non-equation text
\par\end{center}%
\end{minipage}}{\small\par}
\par\end{center}
\begin{itemize}
\item Content
\item Content
\end{itemize}
\end{frame}
\end{document}
user42459
  • 207
  • 1
    I can reproduce in LyX, but I don't know the answer. It's usually recommended to provide the LaTeX so that the experts around here who don't use LyX can take a look. To do that, go to File > Export > LaTeX (pdflatex) or whichever flavor you prefer, and post the contents of the resulting .tex file. By the way, nice clear question with screenshots! -> +1 – scottkosty Mar 03 '20 at 14:14
  • @scottkosty Thank you so much. I added tex. – user42459 Mar 03 '20 at 17:17
  • @WillieWong Thank you very much for your tip. I added the entire tex code now. – user42459 Mar 03 '20 at 17:52
  • 1
  • @barbarabeeton It does seem related. But I can't understand where to put which code into my tex code. Where should I put \pretocmd\start@align in my code? Where should I put \if@minipage\kern-\topskip\kern-\abovedisplayskip\fi ? And what are those {}{} ? – user42459 Mar 07 '20 at 02:27
  • 1
    The block of code that begins \usepackage{etoolbox} would be placed in your preamble, exactly as it appears. This should be the equivalent of inserting this at the top of a minipage that begins with an align: \kern-\topskip\kern-\abovedisplayskip; but of course that would have to be put into every minipage that starts with an align. (This "direct" approach would be needed if the minipage begins with equation or a display that isn't based on align.) – barbara beeton Mar 07 '20 at 03:25
  • @barbarabeeton Thank you! It does remove the gap. But actually too much perhaps. Now it looks like http://prntscr.com/rd3r9z. Is there a way to adjust the margin? – user42459 Mar 07 '20 at 20:20
  • 1
    I've finally had a chance to test it. Forget the \kern-\topskip. You need only the \kern-\abovedisplayskip. – barbara beeton Mar 07 '20 at 20:52
  • @barbarabeeton This worked! Thank you very much! – user42459 Mar 08 '20 at 04:18

1 Answers1

2

Although the question Spurious space above align environment at top of page/minipage addresses this problem, the advice there isn't perfect.

The suggestion is to apply this spacing adjustment before the display that begins a minipage: \kern-\topskip\kern-\abovedisplayskip. But this is the result (shortening the example in the present question to the absolute minimum):

\documentclass{beamer}
\usepackage{amsmath}

\begin{document}

\begin{frame} %[t]{Title}                                                       
\centering
{\small{}}%                                                                     
\fbox{\begin{minipage}[t]{0.8\columnwidth}%                                     
\kern-\topskip \kern-\abovedisplayskip
{\small{}
\begin{align*}
 & equation
\end{align*}
}%                                                                              
\end{minipage}}
\end{frame}

\end{document}

output of example code

The proper adjustment is to remove the \topskip adjustment:

\documentclass{beamer}
\usepackage{amsmath}

\begin{document}

\begin{frame} %[t]{Title}                                                       
\centering
{\small{}}%                                                                     
\fbox{\begin{minipage}[t]{0.8\columnwidth}%                                     
\kern-\abovedisplayskip
{\small{}
\begin{align*}
 & equation
\end{align*}
}%                                                                              
\end{minipage}}
\end{frame}

\end{document}

with the following result:

enter image description here

The function of \topskip is by default to establish the vertical position of the baseline of the first line on a page. That doesn't apply when a page begins with a math display.

  • I do not understand a sense of the {\small{}} in OP code. Isn't it better to dropout it (and by this remove clutter in code)? – Zarko Mar 08 '20 at 18:27
  • @Zarko -- I agree that {\small{}} doesn't make sense (to me), but after trying the example without it, and finding that it did make a slight difference in the appearance, I decided to leave it in. – barbara beeton Mar 08 '20 at 18:30
  • `\documentclass{beamer} \begin{document} \begin{frame}[t]{Title} \begin{center} \fbox{\begin{minipage}[t]{0.8\columnwidth}% \kern-\abovedisplayskip \begin{gather} c_1^2 = a_1^2 + b_1^2 \end{gather} \end{minipage}} \end{center} \begin{itemize} \item Content \item Content \end{itemize} \end{frame}

    \begin{frame}[t]{Title} \begin{center} \fbox{\begin{minipage}[t]{0.8\columnwidth}% \centering non-equation text \end{minipage}} \end{center} \begin{itemize} \item Content \item Content \end{itemize} \end{frame} \end{document} ` gives me the same result

    – Zarko Mar 08 '20 at 19:10
  • @Zarko -- What do you mean by "the same result"? The space above the display material is slightly larger than the space between the bottom of that and the end of the \fbox, but not the very large gap shown in the original question. (Determining why those two spaces aren't the same will require some serious debugging, which I will try to do, but not immediately.) – barbara beeton Mar 08 '20 at 23:55
  • In comment I just like to show code for comparison. When I compare result, i didn't observe difference between solution, which contains {\small{}} and which not. Well, my observation is subjective since didn't made any (objective) measurement . About reason for difference in spaces I agree with you, – Zarko Mar 09 '20 at 00:05