# Vertical spacing around align in a figure

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

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?

• Could you show us a compilable example please? – LaRiFaRi Jul 27 '15 at 14:14
• Done. You probably want to click on the image to have a closer look. – Joachim Breitner Jul 27 '15 at 15:08
• If you don't want gaps or equation numbers, just use \hfil $x=a$\par or \makebox[\textwidth]{$x=a$} although you might want to add a \mathstrut. – John Kormylo Jul 28 '15 at 4:01
• Could you elaborate a bit more on why you want to do such things and how this would look like? I can't think about many cases where an align would be wrapped in a figure. For the few cases, just do \abovedisplayskip=0pt as first line of your figure. – LaRiFaRi Jul 28 '15 at 7:29
• @Larifari, I want the first line of the pages to align. And there are environments derived from align etc. (e.g. lhs2tex), I’m using align only as an example here. – Joachim Breitner Jul 28 '15 at 7:35

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.