Math & ScienceVertical spacing of multiple equations

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Vertical spacing of multiple equations

Post by Cham »

I need some advices or opinions on the way multiple equations should be coded.

For a long time, I was using this way of coding multiple equations (I'm using the book class, in 12pt size):

Code: Select all

\begin{align}
	A &= B, \\ \nonumber \\
	C &= D.
\end{align}
or

Code: Select all

\begin{align*}
	A &= B, \\ \\
	C &= D.
\end{align*}
Now, I prefer using this way :

Code: Select all

\begin{align}
	A &= B, \\[18pt]
	C &= D.
\end{align}
or

Code: Select all

\begin{align*}
	A &= B, \\[18pt]
	C &= D.
\end{align*}
Which way is better ? How the vertical spacing **should** be defined, in LaTeX ?
What are the advantages and inconvenients of each ? Or is there a better way of doing this ?

My "old" way (using \\ \\) gives a vertical spacing which feels a bit too wide. The other way (using \\[18pt]) gives an almost identical output (slightly less wide), but feels a bit more regular.

I need opinions on this, since I may convert all my old codes to the one I currently prefer, but it may be a "mistake".

In case a MWE is needed, here's one (the output of both ways of coding the vertical spacement appears to be identical, but that's because the equations are too simple here.) :

Code: Select all

\documentclass[12pt,letterpaper]{book}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage[left=1.0in,top=1.0in,right=1.0in,bottom=1.0in]{geometry}

\begin{document}

This way :
\begin{align}
        A &= B, \\ \nonumber \\
        C &= D.
\end{align}
and :
\begin{align*}
        A &= B, \\ \\
        C &= D.
\end{align*}
Or this way :
\begin{align}
        A &= B, \\[18pt]
        C &= D.
\end{align}
and :
\begin{align*}
        A &= B, \\[18pt]
        C &= D.
\end{align*}

\end{document}
Last edited by Cham on Fri Jul 24, 2015 4:23 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Vertical spacing of multiple equations

Post by Johannes_B »

The extra double backslash is leaving out an entire line, with a base font size of 12 pt the overall sep of baselines will be 24pt (2\baselineskip). \\[<length>] will add a given length. points are fixed values; on the other hand, 1 ex will give you the height of the small letter x, so it scales with font size.

\baselineskip is size dependant as well, i would probably use \\[1.5\baselineskip] as 12 times 1.5 coincidentally is 18, the value you found suiting. EDIT: This is wrong, please see below why.

To say more about this, i don't have the mathematical (typesetting) knowledge.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Vertical spacing of multiple equations

Post by Cham »

Thanks for the reply, Johannes. You also solved a small "mystery" to me : the meaning of the 1ex command ! :)
Last edited by Cham on Fri Jul 24, 2015 4:35 pm, edited 1 time in total.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Vertical spacing of multiple equations

Post by Cham »

Hmmm, the \\[1.5\baselineskip] gives a larger spacement than \\[18pt] :

Code: Select all

\documentclass[12pt,letterpaper]{book}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage[left=1.0in,top=1.0in,right=1.0in,bottom=1.0in]{geometry}

\begin{document}
\noindent
\begin{align}
        A &= B, \\[1\baselineskip]
        C &= D.
\end{align}
\begin{align}
        A &= B, \\[18pt]
        C &= D.
\end{align}
\begin{align}
        A &= B, \\[1.5\baselineskip]
        C &= D.
\end{align}

\end{document}
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Vertical spacing of multiple equations

Post by rais »

Cham wrote:Hmmm, the \\[1.5\baselineskip] gives a larger spacement than \\[18pt]
yes, the \baselineskip within normal text of 12 pt is set to 14.5 pt (see the definition of \normalsize in bk12.clo).
Within {align} environment, it's even higher (17.5 pt).
You can let LaTeX tell you, how big it really is with
\the\baselineskip

KR
Rainer
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: Vertical spacing of multiple equations

Post by Johannes_B »

Thanks for noting my error (left an edit note above). I never noticed the larger spacing in displayed math, but now, thinking about it, it's logical to be larger. There is space needed to fit sums and limits and fractions.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Vertical spacing of multiple equations

Post by Cham »

So, what vertical separation code you guys are using, when you type multi-equations (align, gather, etc) ? \\ \\, or \\[18pt], or what else ?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Vertical spacing of multiple equations

Post by Stefan Kottwitz »

  • \\ \\ is bad since this adds logical rows where physical space is intended.
  • \\[18pt] is bad since it inserts physical measurement within an otherwise logical structure. It needs to be repeated all the time, can lead to a mistake when forgotten or wrong, so needs additional care. And if you decide to change the space, such as when the font size would be changed or another thing in the layout, you need to find all occurrences to correct each of them.
I adjust \jot once, this is the distance between two consecutive rows in an amsmath multi-line math formula.
  • \setlength{\jot}{18pt} if I really need that absolute value
  • \setlength{\jot}{3ex} to make it scalable with the font, which is better
  • \setlength{\jot}[\baselineskip] (perhaps with a factor) to make it scalable with the line distance, so also with the font height and the line spread.
Alternatively via \addtolength.

Stefan
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Vertical spacing of multiple equations

Post by Cham »

Thanks Stefan,

so how do you code an align environment with, say, two equations ?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Vertical spacing of multiple equations

Post by Stefan Kottwitz »

Cham wrote:so how do you code an align environment with, say, two equations ?
I end the line with the first equation just by \\.

Stefan
LaTeX.org admin
Post Reply