1

Math environments like align put vertical space around them, to separate them from the text. This is all well, and if I wanted to change that, I could check this question.

However, these environments also add vertical space (one \abovedisplayskip) above the math environment inside a floating figure. This way, the first line of the page is not aligned with the other first lines, which looks strange and wastes spaces.

As a MWE, I have this

\documentclass{article}
\usepackage{showframe,amsmath}

\begin{document}

This is regular text on the first line
\begin{align*}
\text{There is space before this, which is good}
\end{align*}
More regular textx.
\clearpage
\begin{figure}[t]
\begin{align*}
\text{This is not on the first line}
\end{align*}
\caption{A figure with extra space}
\end{figure}
Some text for the second page.
\end{document}

which produces

Extra space on the right!

Am I expecting too much from Tex if I expect that space not to be there? And is there a way to fix this centrally, without affecting other vertical spaces around math environments?

1 Answers1

1

I do not know how to do this for the case of several aligns in one figure. I have never seen anyone using display math in a figure and I do not get the value of doing so. So I just give the solution for getting rid of \abovedisplayskip in figures also this is not what you are looking for.

% arara: pdflatex

\documentclass{article}
\usepackage{amsmath}
\usepackage{etoolbox}
\makeatletter
\AtBeginEnvironment{figure}{\def\@floatboxreset{\setlength{\abovedisplayskip}{0pt}}}
\makeatother

\begin{document}    
    This is regular text on the first line
    \begin{align*}
        \text{There is space before this, which is good}
    \end{align*}
    More regular text.
    \clearpage
    \begin{figure}
        \begin{align*}
            \text{This is on the first line}
        \end{align*}
        \caption{A figure without any extra space}
    \end{figure}
    Some text for the second page.
\end{document}

Your case is really hard to code as you have to check, whether it is the first or any other align inside your float. Maybe you should better write your own environment myfirstalign* or alike.

LaRiFaRi
  • 43,807