2

When typesetting a chain of equations with long expressions, I like to put everything on the right hand side of the equation sign to avoid overfull boxes or the use of multlined & friends. Currently I do this via the align environment where I place the ampersands as =&, but I just noticed that this removes the space between the = and the expression.

IISC equation + split and alignat behave the same. I browsed a number of the numerous questions on equation alignment but didn't find this exact case yet. I'd be glad for any pointers on how to achieve this.

If this is not easily possible, I may consider aligning the first line with the = or even moving it a bit to the left.


Here is an MWe:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
    This is what I'd like to avoid.
    \begin{align*}
        \text{First very long expression}
        &= \text{Second very long expression that might cause an overfull box}\\
        &= \text{Third very long expression}
    \end{align*}
    This is the alignment that I would like to achieve, but the \verb|\hphantom| seems like an ugly workaround.
    \begin{align*}
        &\hphantom{=.} \text{First very long expression}\\
        &= \text{Second very long expression that might cause an overfull box}\\
        &= \text{Third very long expression}
    \end{align*}
    Unfortunately \verb|align| removes the space between \verb|=| and expression when placing the \verb|&| right of the \verb|=|.
    \begin{align*}
        & \text{First very long expression}\\
        =& \text{Second very long expression that might cause an overfull box}\\
        =& \text{Third very long expression}
    \end{align*}
\end{document}

which renders as MWE result

2 Answers 2

4

={}& will give \mathrel = just as $=$ gives a no space after = but $={}$ will give space after =.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}
Unfortunately \verb|align| removes the space between \verb|=| and expression when placing the \verb|&| right of the \verb|=|.
    \begin{align*}
        & \text{First very long expression}\\
        ={}& \text{Second very long expression that might cause an overfull box}\\
        ={}& \text{Third very long expression}
    \end{align*}
\end{document}
4
  • Ah, thanks! I guess I could use a custom macro for ={}, then. From this answer I understand that this is not an issue of the specific math environment, but due to tex kerning rules - is that correct?
    – CallMeStag
    Mar 4, 2022 at 9:48
  • @CallMeStag yes and no, tex's spacing rules for a \mathrel like = don't add the space if it is at the end of the list, that is primitive tex behaviour, but the specific thing about ams alignments is that they add {} automatically to the start of the right hand side so that the standard x&=y usage ends up as $x$\relax ${}=y$ and gets the same layout as $x=y$ Mar 4, 2022 at 9:53
  • All right, thanks for the explanation. So probably no straightforward solution without manual work or fiddling with ams internals.
    – CallMeStag
    Mar 4, 2022 at 9:58
  • @CallMeStag adding & is manual positioning of an alignment point, adding {}& is only two characters more and is manual positioning of an alignment point that avoids end-of-math spacing on the left. I've never seen these as much different in terms of ease of use. Mar 4, 2022 at 10:01
3

An alternative placement would be with the first expression slightly on the left of the aligned equals signs.

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

\usepackage[nopar]{lipsum}

\begin{document}

\lipsum[1][1-4]
\begin{align*}
\lefteqn{\text{First very long expression}}
\quad&\\
   &= \text{Second very long expression that might cause an overfull box}\\
   &= \text{Third very long expression}
\end{align*}
\lipsum[2][1-4]
\begin{align*}
\mathmakebox[1em][l]{\text{First very long expression}}&\\
   &= \text{Second very long expression that might cause an overfull box}\\
   &= \text{Third very long expression}
\end{align*}
\lipsum[3][1-4]

\end{document}

The second way is less cryptic, but essentially it does just like the first one.

enter image description here

You must log in to answer this question.

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