# Equation number messes with horizontal alignment

I have an equation with long lines that doesn't align very well:

Equations (9) and (10) are identical except for the equation numbers, and the first line of either equation marginally fits into the text area. LaTeX didn't generate any overflow warnings, but clearly the first line of Equation (10) spills out of the text area. Apparently this undesirable behavior has something to do with the equation number being longer than LaTeX can fit on the second line. How can I make Equation (10) appears as Equation (9), without the indentation and with the equation number on the second line?

The source follows:

\documentclass{article}
\usepackage{amsmath,lipsum}
\begin{document}
\setcounter{equation}{8}
\lipsum[1][1-3]
\begin{align}
\nonumber 0
&= \framebox[325pt]{line} \\
&= \framebox[295pt]{line}
\end{align}
\lipsum[1][4-6]
\begin{align}
\nonumber 0
&= \framebox[325pt]{line} \\
&= \framebox[295pt]{line}
\end{align}
\lipsum[1][7-9]
\end{document}

• Can you report that here? github.com/latex3/latex2e/issues Mar 25, 2019 at 12:26
• @DavidCarlisle Done! Mar 25, 2019 at 12:59
• Fastest fix: Use mathtools and \mathrlap{...} on the contents (after &=) on the shortest line. In any case, when I edit, I will usually break up the 325pt line, as math lines whos lengths are comparable to the text width is much less readable. Mar 25, 2019 at 17:40
• @daleif In my case, breaking up the first line actually makes the equation much more ugly and illegible. An alternative hack I'm using: \mkern-18mu after the second line, with the length adjusted as needed. Mar 25, 2019 at 20:34
• @daleif even if it's bad style in the docuemnt I think amsmath.mathtools align shouldn't overrun without any overfull box warning. I think I have seen this before somewhere but I can't recall where or find it just at the moment. Mar 25, 2019 at 21:26

In the “centered equations with tags on the right” mode, the “indent” from the left margin to the align structure should only be accepted when it is decreasing. Unfortunately, the macro \x@calc@shift@rc for this mode does not guard against a possible increasing “indent”. Your example shows how the “indent” increases from (9) to (10).

\documentclass{article}
\usepackage{amsmath,lipsum}

\usepackage{etoolbox}
\makeatletter
\patchcmd\x@calc@shift@rc
{% The \eqnshift@ could end up increasing!
\eqnshift@\displaywidth
\global\divide\eqnshift@\tw@
}
{% Use \dimen@ to perform the calculations instead
\dimen@\displaywidth
\divide\dimen@\tw@
% Update \eqnshift@ if and only if the result decreases
\ifdim\dimen@<\eqnshift@
\global\eqnshift@\dimen@
\fi
}
{}
{}
\makeatother

\begin{document}
\setcounter{equation}{8}
\lipsum[1][1-3]
\begin{align}
\nonumber 0
&= \framebox[325pt]{line} \\
&= \framebox[295pt]{line}
\end{align}
\lipsum[1][4-6]
\begin{align}
\nonumber 0
&= \framebox[325pt]{line} \\
&= \framebox[295pt]{line}
\end{align}
\lipsum[1][7-9]
\end{document}


Addendum: I have reported the fix on the GitHub issue tracker.

Use a phantom option inside \adjustbox command to create a phantom tag as follows

\adjustbox{phantom}{(\arabic{equation})}

If you plan to use this frequently define a \tagphantom command

\newcommand{\tagphantom}{\adjustbox{phantom}{(\arabic{equation})} \notag}

\documentclass{article}
\usepackage{amsmath,lipsum}
\begin{document}
\setcounter{equation}{8}
\lipsum[1][1-3]
\begin{align}
\nonumber 0
&= \framebox[325pt]{line} \\
&= \framebox[295pt]{line}
\end{align}
\lipsum[1][4-6]
\begin{align}
&= \framebox[295pt]{line} \tagphantom  \\
&=\framebox[295pt]{line}
\end{align}
\lipsum[1][7-9]
\end{document}


Another way to do it is to use split whenever you do not want the tag to change the space available for each line in align, but this will bring the tag to the vertical middle

\documentclass{article}
\usepackage{amsmath,lipsum}
\begin{document}
\setcounter{equation}{8}
\lipsum[1][1-3]
\begin{align}
\nonumber 0
&= \framebox[325pt]{line} \\
&= \framebox[295pt]{line}
\end{align}
\lipsum[1][4-6]
\begin{align}
\nonumber 0
&= \framebox[325pt]{line} \\
&= \framebox[295pt]{line}
\end{align}
\lipsum[1][7-9]
\end{document}

• What if we only want to number the second line?
– user156344
Mar 25, 2019 at 17:29
• The first suggestion above can be implemented more simply with \hphantom{\tagform@\theequation}\nonumber, without the need to include a new package. However, the phantom tag does nothing to help with the alignment; it arguably worsens the situation by making the first line longer. Neither suggestion is a solution because the first line is shortened; an overfull warning appears when the first line is restored to its original length. Mar 25, 2019 at 20:26