50

I need to display math in my report, but is it possible to remove the vertical space around align*?

A little example is the following (where I just want the align* to have the same vertical space as a \\

\documentclass[10pt,danish,a4paper,oneside,fleqn]{report}

\usepackage[english]{babel}
\usepackage{amsmath}

\begin{document}

ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
\begin{align*}
  A{\cap}B\ & =\ {\left\{{b,d,e}\right\}}{\;}{\cap}{\;}{\left\{{a,b,f,g}\right\}}   \\
  \nonumber\ & =\ {\left\{{b}\right\}}
\end{align*}
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss \\
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss

\end{document}
4
  • 1
    Please, show a minimal example of what you find wrong.
    – egreg
    Mar 9, 2012 at 13:41
  • You shouldn't, it makes the math harder to read
    – daleif
    Mar 9, 2012 at 13:55
  • 3
    The math is taking to much space in my report as I have a page limit
    – The87Boy
    Mar 9, 2012 at 13:56
  • To remove the space you may use the minipage environment. Use \begin{minipage}[t][height of text][t]{yourtextsize} and you will contain the height of the align environment.
    – Vag
    Apr 24, 2018 at 14:42

4 Answers 4

48
\documentclass[10pt,danish,a4paper,oneside,fleqn]{report}

\usepackage[english]{babel}
\usepackage{amsmath,lipsum}

\begin{document}
\setlength{\abovedisplayskip}{0pt}
\setlength{\belowdisplayskip}{0pt}
\setlength{\abovedisplayshortskip}{0pt}
\setlength{\belowdisplayshortskip}{0pt}

\lipsum*[2]  
\begin{align*}
  A\cap B & = \{b,d,e\} \cap \{a,b,f,g\} \\
          & = \{b\}
\end{align*}
\lipsum[3]

\end{document}

Note, however, that this is very poor typography. (lipsum is just to generate dummy text.)

The four parameters state how much vertical space is inserted between text and a math display. The "short" version is used for equation, when the last line of text is short.

You should also check the way you're inputting math. You're using too much redundant braces (that in some cases give very bad results). It's quite rare to use explicit spacing commands in math.

Here's the result of typesetting the test file

enter image description here

This is the principle. In case you use font size changing commands, you have to tell LaTeX that you want this zero spacing in all sizes by putting this in the preamble

\usepackage{etoolbox}
\newcommand{\zerodisplayskips}{%
  \setlength{\abovedisplayskip}{0pt}%
  \setlength{\belowdisplayskip}{0pt}%
  \setlength{\abovedisplayshortskip}{0pt}%
  \setlength{\belowdisplayshortskip}{0pt}}
\appto{\normalsize}{\zerodisplayskips}
\appto{\small}{\zerodisplayskips}
\appto{\footnotesize}{\zerodisplayskips}

so that the example becomes

\documentclass[10pt,danish,a4paper,oneside,fleqn]{report}

\usepackage[english]{babel}
\usepackage{amsmath,lipsum}
\usepackage{etoolbox}
\newcommand{\zerodisplayskips}{%
  \setlength{\abovedisplayskip}{0pt}%
  \setlength{\belowdisplayskip}{0pt}%
  \setlength{\abovedisplayshortskip}{0pt}%
  \setlength{\belowdisplayshortskip}{0pt}}
\appto{\normalsize}{\zerodisplayskips}
\appto{\small}{\zerodisplayskips}
\appto{\footnotesize}{\zerodisplayskips}

\begin{document}

\lipsum*[2]  
\begin{align*}
  A\cap B & = \{b,d,e\} \cap \{a,b,f,g\} \\
          & = \{b\}
\end{align*}
\lipsum[3]

\end{document}
8
  • Thanks for the comments, but the setlength's did not do it :(
    – The87Boy
    Mar 9, 2012 at 14:04
  • It does. You probably have other display environments, I'll update my answer
    – egreg
    Mar 9, 2012 at 14:06
  • It stills give me the same result, no space removed
    – The87Boy
    Mar 9, 2012 at 14:29
  • 3
    Works for me as well, but makes me wondering why it doesn't work when the \setlength commands are set in the preamble.
    – Philipp
    Mar 9, 2012 at 15:04
  • 1
    @Philipp The parameters' values are set by \normalsize and other size changing commands, which might account for the OP's problem.
    – egreg
    Mar 9, 2012 at 15:17
23

Use an inline equation (which adds no vertical space), place the macro \displaystyle within it (so it looks like a normal equation), place aligned within it (for alignment), and enclose it within {\centering ... \par} (to center without adding unnecessary vertical space).

{\centering
  $ \displaystyle
    \begin{aligned} 
       A{\cap}B\ & =\ {\left\{{b,d,e}\right\}}{\;}{\cap}{\;}{\left\{{a,b,f,g}\right\}}   \\
       \nonumber\ & =\ {\left\{{b}\right\}} 
    \end{aligned}
  $ 
\par}%Necessary for centering to work

It's a bit ugly if you're doing it a lot, but in my case it was handy because I wanted to remove vertical space from one or two equations (so they'd fit within a table) but not affect any others.

2
  • There is a little typo in your code - \displaysyle instead of \displaystyle.
    – Eenoku
    Nov 21, 2015 at 22:29
  • 1
    Thanks, this is great! It also allows using \raggedright and \raggedleft for respectively left- and right- alignment. I'm making it into a macro for reuse :-) Sep 10, 2017 at 19:44
9

Egreg's solution has unwanted spaces at the end of the lines. They have to be suppressed by putting % at the end.

\usepackage{etoolbox}
\newcommand{\zerodisplayskips}{%
  \setlength{\abovedisplayskip}{0pt}%
  \setlength{\belowdisplayskip}{0pt}%
  \setlength{\abovedisplayshortskip}{0pt}%
  \setlength{\belowdisplayshortskip}{0pt}}
\appto{\normalsize}{\zerodisplayskips}
\appto{\small}{\zerodisplayskips}
\appto{\footnotesize}{\zerodisplayskips}
1
  • I've updated egreg's answer.
    – Roly
    Dec 31, 2016 at 9:30
3

You can use \vspace{-0.5cm} locally above each \begin{align*}

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Apr 4, 2022 at 6:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .