1

I am currently having outrageous vertical space before and after I use align.

For a bit of context, I used \onehalfspacing to make my document a bit clearer. However, it becomes ugly when I using align. For instance, here is a picture of what it looks like compared to when I am using array (and in fact any time I need to write maths using "$$") :

enter image description here

I would like to reduce this white space when I use align, but I can't find anything relevant enough. Since I am searching for something that works anytime without always repeating the command each time I have to use align, I was thinking of creating a new environment, but I don't know how to make one like align.

Thanks a lot for your help !

EDIT : Here is the code I used to take the picture :

\documentclass{article}
\usepackage[utf8]{inputenc}

%---------------

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} 
\usepackage[french]{babel} 
\usepackage[cyr]{aeguill} 

%--------------- 

\usepackage{fancyhdr}
\usepackage[top=3cm, bottom=3cm, left=3cm, right=3cm]{geometry}
\usepackage{setspace}


%---------------

\onehalfspacing 
%\setlength{\parskip}{0cm} %not usefull

%--------------- 

\usepackage{amsmath, amssymb, amsthm} 
\usepackage{mathrsfs}
\usepackage{etoolbox}
\usepackage{stmaryrd}

\title{Tests Overleaf}
\date{\today}

\begin{document}

\maketitle

\section{Introduction}

------------------------------------------------------------------------------------------

I am using array : 

$$\begin{array}{cccccc}
    f : & A & \times & B & \longrightarrow & C \\
    & x & ; & y & \longmapsto & xy 
\end{array}$$

------------------------------------------------------------------------------------------

I am using align* : 

\begin{align*}
    a \times (b+c) & = a \times b + a \times c\\
    & = a \times b + a \times c + 0
\end{align*}

------------------------------------------------------------------------------------------

\end{document}
6
  • 2
    you should never use $$ in latex. It is hard to tell you how to correct the markup making over-large spaces if you do not show the markup. Please always include a complete small document that produces the image shown, add it as a code block to teh question so people can test answers. – David Carlisle Jan 25 '20 at 16:01
  • 3
    do you have a blank line in the source before \begin{align} ? You should never have a blank line before any display math construct. – David Carlisle Jan 25 '20 at 16:02
  • @DavidCarlisle Yes I have one, but in my documents I don't and I still have a huge gap between my text and my equations. – Matthieu Jentile Jan 25 '20 at 16:22
  • 1
    having a blank line before align is an error (and will produce at least \baselineskip of spurious white space, you also get more for align than for \[ if (as you show here) the last line of the paragraph is short. as it always uses \abovedisplayskip rather than \abovedisplayshortskip but with no example code posted not really possible to give a definite answer just guesses of things you may have done wrong. – David Carlisle Jan 25 '20 at 16:26
  • the space is affected by use of \flushbottom for example, there are so many things it could be.... – David Carlisle Jan 25 '20 at 16:27
2

Never have a blank line before any display math, that forces a one-line paragraph with an empty white line before the display. Also $$ is not supported LaTeX syntax so I changed that to \[.

As the line above the equation is short TeX can use the smaller \abovedisplayshortskip if the equation is to the right of the line end, however align is always full width even if visually narrow, so always uses \abovedisplayskip You can use aligned instead in a way similar to you used array, aligned is more suitable than array as it sets the content in display math mode, array is designed for setting matrices of values, and sets each cell in inline math mode.

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}

%---------------

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} 
\usepackage[french]{babel} 
\usepackage[cyr]{aeguill} 

%--------------- 

\usepackage{fancyhdr}
\usepackage[top=3cm, bottom=3cm, left=3cm, right=3cm]{geometry}
\usepackage{setspace}


%---------------

\onehalfspacing 
%\setlength{\parskip}{0cm} %not usefull

%--------------- 

\usepackage{amsmath, amssymb, amsthm} 
\usepackage{mathrsfs}
\usepackage{etoolbox}
\usepackage{stmaryrd}

\title{Tests Overleaf}
\date{\today}

\begin{document}

\maketitle

\section{Introduction}

------------------------------------------------------------------------------------------

I am using array : 
\[
\begin{array}{cccccc}
    f : & A & \times & B & \longrightarrow & C \\
    & x & ; & y & \longmapsto & xy 
\end{array}
\]

------------------------------------------------------------------------------------------

I am using align* : 
\begin{align*}
    a \times (b+c) & = a \times b + a \times c\\
    & = a \times b + a \times c + 0
\end{align*}

------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------

I am using aligned* : 
\[
\begin{aligned}
    a \times (b+c) & = a \times b + a \times c\\
    & = a \times b + a \times c + 0
\end{aligned}
\]

------------------------------------------------------------------------------------------

\end{document}

Alternatively the mathtools extension if amsmath provides a command that enables the use of the short display skip on specific displays where you can tell the previous line will not be close to the top line of the alignment.

You may also want to use

\usepackage[nodisplayskipstretch]{setspace}

so setspace does not mess with this spacing:

enter image description here

4
  • 1
    oh meanwhile I found a bug in setspace package handling of displayskip.... – David Carlisle Jan 25 '20 at 16:48
  • 1
    you may simply want to do \setlegth\abovedisplayskip{8pt plus 2pt} or anything else that you think looks right – David Carlisle Jan 25 '20 at 16:52
  • Well I like the look of aligned. I tried the option on setspace you used but I there's a bug, better not. Thanks ! – Matthieu Jentile Jan 25 '20 at 17:03
  • @MatthieuJentile no the bug is there even without the option (and when I went to log an issue I found it was already logged and I had already posted a workaround) github.com/rf-latex/setspace/issues/1 – David Carlisle Jan 25 '20 at 17:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.