3

As shown below the bottom spacing after the first equation is smaller than it should be to look right. I know I could manually add space, but is there a way to fix this automatically? I do know I should not place equations right after sections but I do feel that it works best in my case.

\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[margin=1.0in]{geometry}
\usepackage{microtype}
\usepackage[fleqn]{mathtools}

\setlength\mathindent{0pt}

\begin{document}
\section*{Test}
\[
  a^2 + b^2 = c^2
\]
This is some test text.
\[
  a^2 + b^2 = c^2
\]
This is some more text.
\end{document}

enter image description here

2 Answers 2

2

I added this after \section: \mbox{}\vspace{-\dimexpr\baselineskip+\topskip}. See ADDENDUM for possible general fix:

\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[margin=1.0in]{geometry}
\usepackage{microtype}
\usepackage[fleqn]{mathtools}

\setlength\mathindent{0pt}

\begin{document}
\section*{Test}
\mbox{}\vspace{-\dimexpr\baselineskip+\topskip}
\[
  a^2 + b^2 = c^2
\]
This is some test text.
\[
  a^2 + b^2 = c^2
\]
This is some more text.
\end{document}

enter image description here

To confirm that the before spacing is correct, one can place text in the \mbox and compare:

enter image description here

I confirmed that it works, regardless of the \parskip value.

ADDENDUM

Not sure if this will break other things, but here, I redefine \[ to apply the prior fix but only if in vertical mode.

\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[margin=1.0in]{geometry}
\usepackage{microtype}
\usepackage[fleqn]{mathtools}
\setlength\mathindent{0pt}

\let\sveqopen\[
\def\[{\ifvmode\mbox{}\vspace{-\dimexpr\baselineskip+\topskip}\fi\sveqopen}

\begin{document}
\section*{Test}
\[
  a^2 + b^2 = c^2
\]
This is some test text.
\[
  a^2 + b^2 = c^2
\]
This is some more text.
\end{document}
4
  • Thanks! Is there a way to do this automatically? Such as an environment that would automatically fix this issue? Commented Mar 30, 2016 at 13:43
  • @cabellicar123 At the moment, I can't think of an auto-fix, but I would in the preamble define \def\fixmath{\mbox{}\vspace{-\dimexpr\baselineskip+\topskip}} and then just use \fixmath in the text, if an equation was needed immediately after a \section. Commented Mar 30, 2016 at 13:47
  • @cabellicar123 See possible general fix in addendum. Commented Mar 30, 2016 at 13:51
  • @cabellicar123 egreg is much more savvy than I, so perhaps the ideal solution would combine both our solutions: \let\sveqopen\[ \def\[{\ifvmode\mbox{}\vspace{\glueexpr-\dimexpr\baselineskip+\abovedisplayskip}\fi\sveqopen}. Commented Mar 30, 2016 at 14:02
3

The first equation uses the “short” skips, because the paragraph before it is empty. You have to make it artificially longer and to back up by a baseline skip plus the above display skip.

\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[margin=1.0in]{geometry}
\usepackage{microtype}
\usepackage[fleqn]{mathtools}

\setlength\mathindent{0pt}

\begin{document}
\section*{Test}
\makebox[.8\linewidth]{}\vspace{\glueexpr-\baselineskip-\abovedisplayskip}
\[
  a^2 + b^2 = c^2
\]
This is some test text.
\[
  a^2 + b^2 = c^2
\]
This is some more text.

\end{document}

You will get the normal spacing between the section title and the equation.

enter image description here

Here's a visual proof that the spacing is correct:

enter image description here

5
  • Thanks! This does seem to make the spacing between the section and the equation slightly smaller. Is there a way to keep that while still fixing the spacing on bottom? Commented Mar 30, 2016 at 14:07
  • @cabellicar123 Don't trust your eyes. ;-) I added a visual proof that the distance between base lines is the same.
    – egreg
    Commented Mar 30, 2016 at 14:18
  • Ah you are correct. Perhaps it is a time for my eyes to take a break. Thanks! Commented Mar 30, 2016 at 14:23
  • Is there a way to remove the extra space at the bottom say if I have a section right after the equation as well? Commented Mar 30, 2016 at 17:21
  • @cabellicar123 You get the usual space separating the text and the section title.
    – egreg
    Commented Mar 30, 2016 at 17:39

You must log in to answer this question.

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