2
\documentclass[letterpaper,10pt]{article}
\usepackage{amsmath}
\usepackage{nccmath}

\begin{document}

\begin{align*}
\intertext{what is the vertical spacing here?} \\[-30pt] 1+2 \\
=3
\end{align*}
\end{document}

There is an automatic vertical gap that the \intertext command inserts. I would like to know how many pts that gap is to exactly get rid of it with the \\[...] command explicit since manually adjusting this height gives me the freedom I require. -30pts is close, but it appears no integer value works and the ams manual doesn't specify the exact spacing of the intertext command.

user14554
  • 155

1 Answers1

5

If you add \showoutput to your code, you can see the vertical spaces added by TeX to construct the output page. So,

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\showoutput
\begin{align*}
  top \\
  \intertext{intertext}
  bottom
\end{align*}

\end{document}

yields in your .log:

Completed box being shipped out [1]
\vbox(633.0+0.0)x407.0
.\hbox(0.0+0.0)x0.0
..\kern -72.26999
..\vbox(0.0+0.0)x345.0, glue set 72.26999fil
...\kern -72.26999
...\glue(\parskip) 0.0
...\hbox(0.0+0.0)x345.0, glue set 345.0fil
....\hbox(0.0+0.0)x0.0
....\hbox(0.0+0.0)x0.0
.....\hbox(0.0+0.0)x0.0
......\glue 0.0
......\hbox(0.0+794.96999)x0.0
.......\hbox(0.0+0.0)x0.0, shifted 794.96999
........\kern 0.0
........\glue 0.0 plus 1.0fil minus 1.0fil
......\glue 0.0 plus 1.0fil minus 1.0fil
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0
...\glue 0.0 plus 1.0fil minus 1.0fil
.\glue 16.0
.\vbox(617.0+0.0)x345.0, shifted 62.0
..\vbox(12.0+0.0)x345.0, glue set 12.0fil
...\glue 0.0 plus 1.0fil
...\hbox(0.0+0.0)x345.0
....\pdfcolorstack 0 push {0 g 0 G}
....\hbox(0.0+0.0)x345.0
....\pdfcolorstack 0 pop
..\glue 25.0
..\glue(\lineskip) 0.0
..\vbox(550.0+0.0)x345.0, glue set 457.95108fil
...\write-{}
...\pdfcolorstack 0 push {0 g 0 G}
...\glue(\topskip) 10.0
...\hbox(0.0+0.0)x345.0, glue set 330.0fil
....\hbox(0.0+0.0)x15.0
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0
...\penalty 10000
...\glue(\abovedisplayskip) 10.0 plus 2.0 minus 5.0
...\glue -3.0
...\glue 0.0
...\glue(\baselineskip) 6.60004
...\hbox(8.39996+3.60004)x187.49423, display
....\glue(\tabskip) 157.50575
....\hbox(8.39996+3.60004)x29.98848, glue set 16.49889fil
.....\glue 0.0 plus 1.0fil
.....\hbox(8.39996+3.60004)x0.0
......\vbox(8.39996+3.60004)x0.0
.......\kern 0.0
.......\hbox(8.39996+3.60004)x0.0
........\rule(8.39996+3.60004)x0.0
.....\hbox(6.15079+1.94444)x13.4896
......\mathon
......\hbox(6.15079+1.94444)x13.4896
.......\OML/cmm/m/it/10 t
.......\OML/cmm/m/it/10 o
.......\OML/cmm/m/it/10 p
......\mathoff
....\glue(\tabskip) 0.0
....\hbox(8.39996+3.60004)x0.0
.....\hbox(0.0+0.0)x0.0
......\mathon
......\hbox(0.0+0.0)x0.0
......\mathoff
.....\glue 0.0 plus 1.0fil
....\glue(\tabskip) 157.50575
....\hbox(8.39996+3.60004)x-157.50575
.....\kern -157.50575
....\glue(\tabskip) 0.0
...\penalty 10000
...\glue 0.0
...\penalty 0
...\glue 10.0 plus 2.0 minus 5.0
...\glue(\baselineskip) 4.72137
...\vbox(6.67859+0.0)x345.0
....\hbox(6.67859+0.0)x345.0, glue set 307.19437fil
.....\OT1/cmr/m/n/10 i
.....\OT1/cmr/m/n/10 n
.....\kern-0.27779
.....\OT1/cmr/m/n/10 t
.....\OT1/cmr/m/n/10 e
.....\OT1/cmr/m/n/10 r
.....\OT1/cmr/m/n/10 t
.....\OT1/cmr/m/n/10 e
.....\OT1/cmr/m/n/10 x
.....\OT1/cmr/m/n/10 t
.....\penalty 10000
.....\glue(\parfillskip) 0.0 plus 1.0fil
.....\glue(\rightskip) 0.0
...\penalty 10000
...\glue 10.0 plus 2.0 minus 5.0
...\glue(\baselineskip) 6.60004
...\hbox(8.39996+3.60004)x187.49423, display
....\glue(\tabskip) 157.50575
....\hbox(8.39996+3.60004)x29.98848
.....\glue 0.0 plus 1.0fil
.....\hbox(8.39996+3.60004)x0.0
......\vbox(8.39996+3.60004)x0.0
.......\kern 0.0
.......\hbox(8.39996+3.60004)x0.0
........\rule(8.39996+3.60004)x0.0
.....\hbox(6.94444+0.0)x29.98848
......\mathon
......\hbox(6.94444+0.0)x29.98848
.......\OML/cmm/m/it/10 b
.......\OML/cmm/m/it/10 o
.......\OML/cmm/m/it/10 t
.......\OML/cmm/m/it/10 t
.......\OML/cmm/m/it/10 o
.......\OML/cmm/m/it/10 m
......\mathoff
....\glue(\tabskip) 0.0
....\hbox(8.39996+3.60004)x0.0
.....\hbox(0.0+0.0)x0.0
......\mathon
......\hbox(0.0+0.0)x0.0
......\mathoff
.....\glue 0.0 plus 1.0fil
....\glue(\tabskip) 157.50575
....\hbox(8.39996+3.60004)x-157.50575
.....\kern -157.50575
....\glue(\tabskip) 0.0
...\penalty 10000
...\glue 0.0
...\penalty 0
...\glue(\belowdisplayskip) 10.0 plus 2.0 minus 5.0
...\glue -3.60004
...\glue 0.0 plus 1.0fil
...\glue 0.0
...\glue 0.0 plus 0.0001fil
..\glue(\baselineskip) 23.55556
..\hbox(6.44444+0.0)x345.0
...\pdfcolorstack 0 push {0 g 0 G}
...\hbox(6.44444+0.0)x345.0, glue set 170.0fil
....\glue 0.0 plus 1.0fil
....\OT1/cmr/m/n/10 1
....\glue 0.0 plus 1.0fil
...\pdfcolorstack 0 pop
.\kern 0.0
.\kern -633.0
.\hbox(0.0+0.0)x0.0
..\kern -72.26999
..\vbox(0.0+0.0)x345.0, glue set 72.26999fil
...\kern -72.26999
...\glue(\parskip) 0.0
...\hbox(0.0+0.0)x345.0, glue set 345.0fil
....\hbox(0.0+0.0)x0.0
....\hbox(0.0+0.0)x0.0
.....\hbox(0.0+0.0)x0.0
......\glue 0.0
......\hbox(0.0+794.96999)x0.0
.......\hbox(0.0+0.0)x0.0, shifted 794.96999
........\kern 0.0
........\glue 0.0 plus 1.0fil minus 1.0fil
......\glue 0.0 plus 1.0fil minus 1.0fil
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0
...\glue 0.0 plus 1.0fil minus 1.0fil
.\kern 633.0

It might not be that easy to see, but between top and intertext there is

...\glue 10.0 plus 2.0 minus 5.0
...\glue(\baselineskip) 4.72137

and between intertext and bottom there is

...\glue 10.0 plus 2.0 minus 5.0
...\glue(\baselineskip) 6.60004

These are the vertical skips inserted between the constructions. 10.0 plus 2.0 minus 5.0 both represent \abovedisplayskip and \belowdisplayskip which can stretch depending where the align fits within the regular text block construction. The definition of \intertext inside amsmath.dtx provides mention of these skips.

Soooooo... you can get rid of them using

enter image description here

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align*}
  top \\[\dimexpr-\abovedisplayskip-\baselineskip]
  \intertext{intertext} \\[\dimexpr-\belowdisplayskip-\baselineskip]
  bottom
\end{align*}

\end{document}

However, if the intent is just to make a "comment on the left side of an equation", you could probably also do:

enter image description here

\documentclass{article}

\usepackage{amsmath}

\usepackage{zref-savepos,eso-pic}

\newcounter{lc}
\makeatletter
\newcommand{\leftcomment}[1]{%
  \stepcounter{lc}
  \ifmeasuring@\else
    \zsaveposx{comment-\thelc}% Current location x
  \fi
  \makebox[0pt][r]{%
    \makebox[\dimexpr\zposx{comment-\thelc}sp-\zposx{textblock}sp][l]{#1}%
  }
}
\makeatother

\AddToShipoutPictureBG*{\AtTextLowerLeft{\zsaveposx{textblock}}}% Left margin of text block

\begin{document}

\begin{align*}
  top \\[\dimexpr-\abovedisplayskip-\baselineskip]
  \intertext{intertext} \\[\dimexpr-\belowdisplayskip-\baselineskip]
  bottom
\end{align*}

\begin{align*}
                           f(x) &= ax^2 \leftcomment{intertext1} \\
  \leftcomment{intertext2} g(x) &= bx \tag{eq2}                  \\
                           h(x) &= c
\end{align*}

\end{document}

The idea being eso-pic is to capture the location of the text block left margin, while zref's savepos module allows us to capture the coordinate of a label using TeX's \label-\ref system. Since we use the latter, you'll have to compile twice with every change of the labels.

Werner
  • 603,163
  • +1 for \showoutput and not falling back to TikZ to achieve just some positioning :-) – Daniel Jan 06 '19 at 08:18
  • So I'm having trouble figuring out what is going on here. What is the final answer for \intertext? – user14554 Jan 06 '19 at 09:11
  • Note that your sample doesn't work correctly with the nccmath package, as requested by the OP. – siracusa Jan 06 '19 at 12:10
  • @siracusa: True, and I don't know how to fix that. – Werner Jan 06 '19 at 16:50
  • Ok, so once again, could you explicitly state the exact, final spacing in pts? Because otherwise this just doesn't answer the question, it is much too convoluted when the answer should just be one number. – user14554 Jan 06 '19 at 19:32
  • @user14554: Without nccmath it's 25pt. – Werner Jan 06 '19 at 19:42
  • Alright, thank you for your help and patience. Is there anything in particular that nccmath does? Does it add an extra 5pts or 3pts? Should it just be taken out entirely? All I remember ncc doing is adding the \fleqn, which I don't need if I can use \[-25pt] or flalign. – user14554 Jan 06 '19 at 19:47
  • @user14554: I couldn't resolve the vertical space with using nccmath, so I'm not sure. You can do without it, since amsmath provides fleqn and flalign. – Werner Jan 06 '19 at 19:52
  • Do you know how "flush left" align somehow ends up forcing everything to align on the right-side of the page? That doesn't make sense to me if it is supposed to force text to be left-aligned. I guess it wasn't a solution after all. – user14554 Jan 06 '19 at 20:07
  • @user14554: You often have to add a & on the right-hand side. – Werner Jan 06 '19 at 20:38
  • @user14554: It is actually 25pt plus 2pt minus 5pt in standard 10pt document, which means that the space can be stretched to up to 27pt and shrunk down to 20pt if this would improve the overall page layout. The distance between the \intertext line and the lines above/below it actually depends on other contents on the page. – Circumscribe Jan 07 '19 at 11:38
  • @Werner: I think \glueexpr is more appropriate here than \dimexpr because with that the stretch will also be cancelled out. – Circumscribe Jan 07 '19 at 11:41
  • In which location around or inside of an align environment do you use \glueexpr? – user14554 Jan 07 '19 at 22:11
  • 1
    @user14554: I don't use \glueexpr. Instead, I used \dimexpr. However, \abovedisplayskip and \belowdisplayskip are actually glue expressions that can shrink or expand, depending on the content of the document on the page the align appears in. Specifically, as Circumscribe mentions, \abovedisplayskip (and \belowdisplayskip) has a "length" of 10pt plus 2pt minus 5pt. So that "length" can be as short as 5pt (10pt minus 5pt) or as long as 12pt (10pt plus 2pt). \glueexpr keeps the "glue" (the plus and minus parts) while \dimexpr removes them... – Werner Jan 07 '19 at 22:27
  • @user14554: ... you seemed interested in a fixed value rather than an explanation, hence my suggestion to use 25pt (which was 10pt for \abovedisplayskip/\belowdisplayskip without the glue + 15pt for \baselineskip). With the glue, it would be anything between 20pt (10pt + 15pt minus 5pt) and 27pt (10pt + 15pt plus 2pt). – Werner Jan 07 '19 at 22:31
  • See the problem is it shouldn't be a "range" of values, my lines aren't in several places at once like some quantum superposition, it is one finite length, it should just be one value and then that's it. So all this glue and displayskip just doesn't help. – user14554 Jan 07 '19 at 22:57
  • @user14554: TeX was written with the optimal layout of paragraph and math content in mind. Lines are read in and than spacing is adjusted so that the typesetting is mathematically optimal. In order for this optimality to exist, some stretch is required between word, math content and other things so that adjustments can be made to improve the layout. It's an essential part of TeX. If you want to remove this, specifically for equations, then you can add \setlength{\abovedisplayskip}{\dimexpr\abovedisplayskip} (likewise for \belowdisplayskip and others) to your preamble... – Werner Jan 07 '19 at 23:05
  • 1
    @user14554: ... it'll remove the "flexible spacing" that you loath. Removal of this in other areas within the document may result in bad alignment. Similar to comparing \raggedright with the regular typesetting of paragraphs (\justifying if you're using ragged2e). Of course, you're not forced to use (La)TeX... – Werner Jan 07 '19 at 23:07