LaTeX forum ⇒ Math & ScienceVertical spacing of multiple equations

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

Vertical spacing of multiple equations

Postby Cham » Fri Jul 24, 2015 4:03 pm

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):

  1. \begin{align}
  2. A &= B, \\ \nonumber \\
  3. C &= D.
  4. \end{align}

or
  1. \begin{align*}
  2. A &= B, \\ \\
  3. C &= D.
  4. \end{align*}


Now, I prefer using this way :

  1. \begin{align}
  2. A &= B, \\[18pt]
  3. C &= D.
  4. \end{align}

or
  1. \begin{align*}
  2. A &= B, \\[18pt]
  3. C &= D.
  4. \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.) :
  1. \documentclass[12pt,letterpaper]{book}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{amsmath}
  4. \usepackage{amsfonts}
  5. \usepackage{amssymb}
  6. \usepackage{mathtools}
  7. \usepackage[left=1.0in,top=1.0in,right=1.0in,bottom=1.0in]{geometry}
  8.  
  9. \begin{document}
  10.  
  11. This way :
  12. \begin{align}
  13. A &= B, \\ \nonumber \\
  14. C &= D.
  15. \end{align}
  16. and :
  17. \begin{align*}
  18. A &= B, \\ \\
  19. C &= D.
  20. \end{align*}
  21. Or this way :
  22. \begin{align}
  23. A &= B, \\[18pt]
  24. C &= D.
  25. \end{align}
  26. and :
  27. \begin{align*}
  28. A &= B, \\[18pt]
  29. C &= D.
  30. \end{align*}
  31.  
  32. \end{document}
Last edited by Cham on Fri Jul 24, 2015 4:23 pm, edited 1 time in total.

Tags:

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

Postby Johannes_B » Fri Jul 24, 2015 4:21 pm

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: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Fri Jul 24, 2015 4:28 pm

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: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Fri Jul 24, 2015 4:35 pm

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

  1. \documentclass[12pt,letterpaper]{book}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{amsmath}
  4. \usepackage{amsfonts}
  5. \usepackage{amssymb}
  6. \usepackage{mathtools}
  7. \usepackage[left=1.0in,top=1.0in,right=1.0in,bottom=1.0in]{geometry}
  8.  
  9. \begin{document}
  10. \noindent
  11. \begin{align}
  12. A &= B, \\[1\baselineskip]
  13. C &= D.
  14. \end{align}
  15. \begin{align}
  16. A &= B, \\[18pt]
  17. C &= D.
  18. \end{align}
  19. \begin{align}
  20. A &= B, \\[1.5\baselineskip]
  21. C &= D.
  22. \end{align}
  23.  
  24. \end{document}

rais
Posts: 175
Joined: Sun Nov 16, 2014 8:51 pm

Postby rais » Fri Jul 24, 2015 6:21 pm

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: 3883
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Fri Jul 24, 2015 7:35 pm

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: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Mon Jul 27, 2015 4:15 pm

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: 9152
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Mon Jul 27, 2015 5:07 pm

  • \\ \\ 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
Site admin

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Mon Jul 27, 2015 6:22 pm

Thanks Stefan,

so how do you code an align environment with, say, two equations ?

User avatar
Stefan Kottwitz
Site Admin
Posts: 9152
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Mon Jul 27, 2015 7:12 pm

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
Site admin


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 4 guests