# Relation spacing error using =& in aligned equations

The middle equation in the following example seems to have wrong spacing around the = sign. The only difference is that I used =& for aligning around the = sign rather than &=.

This worries me, because sometimes I want to emulate "multline equations", and I want the equations to be aligned like that but without putting an = sign at all.

Is it known, explainable behaviour? I.e., is it a bug or a feature?

\documentclass{minimal}
\usepackage{amsmath}
\begin{document}
$a=b$
\begin{align*}
a =& b\\
c =& d
\end{align*}
\begin{align*}
a &= b\\
c &= d
\end{align*}
\end{document}


• There's nothing that prevents you to put anything you want after &. Please, add an example of what you mean by "emulate multiline equations". For getting the space right, use &=. But also ={}& can work. Jan 14 '12 at 11:46
• Does &\phantom{=} work as well? Jan 14 '12 at 11:56
• @egreg: by "emulate multiline equations" I meant a run-away right-hand side, like the example you present in your answer. I would like to achieve that via \begin{align} a=&axy+b\\&+y\end{align}, but it gives the wrong spacing, as I argued. Both ={} and &\phantom{=} seem to work, though. Jan 14 '12 at 22:36

The technical reason is that the align environment adds an empty math object {} to the beginning of the second cell in each aligned column, but doesn't add it to the end of the first one. This is precisely so that the equals sign behaves as though it comes between two variables when you write &=. I honestly can't figure out why it doesn't add one in the first cell also; although it does occasionally change the spacing (such as when writing =&) it never seems to do so in a way that is obviously wrong.

As others have suggested, you can write ={}& when you want the equals sign to have the correct spacing.

• The specification of the alignment is (roughly) \hfil$#$&${}#$\hfil, so with a&=b TeX sees $a$ in the first cell and ${}=b$ in the second. With a=&b this becomes $a=$ and ${}b$ that doesn't insert a thick space after the =. Jan 14 '12 at 15:55
• Right (that's how the TeXbook defines its alignment macro, anyway); but why not $#{}$&${}#$? It would put a double {}{} between every column, but when would that actually cause a visible error? Jan 14 '12 at 15:58
• Programmers' decision to define a uniform syntax? :) Jan 14 '12 at 16:04
• @egreg -- programmer's decision, but the programmer was knuth. this is inherited from plain tex. to test it, use the code on p.191 of the texbook, just before exercise 5.19. input it twice, once with &= and once with =&, then tex it. you'll get the same bad spacing that comes from amsmath. i've found this commentary regarding the "decision" on pp.190-191: "Multi-line displays usually consist of several equations that should be lined up by their = signs", and "For example, every right-hand side often begins with an = sign." may be something more in tex.web, but didn't check. Jan 14 '12 at 20:22
• I've figured out why do not add one in the first cell. Consider A&=-B. If add in both cell, then the minus sign would be recognized as an binary operator, thus cause extra space between minus sign and B May 14 '20 at 7:58

It is a feature, and an important one: it is simple and efficient for the vast majority of cases, because quite frequently align is used for aligning successive rows at a relation symbol. With &= you are guaranteed to get the correct spacing around the = sign.

On the other hand, sometimes one can need also to "align after the equals". There are various ways to accomplish this task.

For example, if the right hand side of an equation to be aligned is too long, you can use aligned:

\begin{align}
a &= b\\
c &= \!\begin{aligned}[t]
&axy+b\\
&+y
\end{aligned}
\end{align}


This is by no means a "workaround": it marks correctly what one is going to achieve (apart from a small adjustment that may indeed qualify as a small bug, but would also be there with a =& syntax).

Why did the developers of amsmath chose this instead of =&? Well, one reason is that they borrowed some ideas from the TeXbook. But, more importantly, many cases of align follow the pattern

\begin{align}
x &= <some expression> \\
&= <a development of that expression> \\
&= <a further development>
\end{align}


where a =& syntax would be cumbersome.

In some cases it can be handy to align differently; I've found some of them and

a = {} &


solves the spacing problem.

• The first solution that you outline still gives a slightly incorrect spacing. Change the first equation to $a&=a$ to make it more evident: the two $a$ in the right-hand sides are not perfectly aligned. Jan 14 '12 at 22:29
• Could you please give more arguments in favor of "it's a feature"? In the other answer, Ryan Reich seems to think the opposite, and I also do not see any good reason after reading the rest of your message. Unless I am misunderstanding you, the two "solutions" you suggest are workarounds to get the behaviour I was expecting. Jan 14 '12 at 22:34

In the align environment, it treats A & B as $A$ ${}B$. which means if you input

\begin{align*}
A  &  B  \\
C  &  D
\edn{align*}


What it actually outputs is a tabular with four items like

That's how align works.

As for your question, the spacing is added only when there's something after it. If nothing is after the "=", no space would be added.

I've also figured out why they do not add {} in the first cell $A{}$ ${}B$. Consider A&=-B. If add {} in both cell, the spacing between the "=" and "-" would become bigger(space is added twice). Also, "=" should be on the right-hand side, or the minus sign would be recognized as an binary operator, thus cause extra space between minus sign and B.

You can see none but the first one made the correct spacing.

In real life, the Relation sign is often followed by Ordinary, But to proceed with Ordinary/Binary/Operator. Thus, the author made suggestions "=" must on the right so that character after "=" could be classified (Ord/Bin/Op) correctly.

In our little example, only when the Rel is on the right can the TeX figured out the minus sign as Ordinary rather than a Binary.

As for your question, if you don't mind adjusting the spacing manually, you can use A={} & B. or you can use

A & = B \\
&\phantom{\;=\;}C


The \; is normally added by TeX automatcally.

• Thanks! This is useful information, even though technically it is a slightly different issue than the one I had in my question: in one case the problem is the $-$ that needs something around it to behave as a binary operator, in the other it's $=$ that needs something around it to behave as a relation symbol (and these two classes of symbols are treated differently in Tex). May 14 '20 at 9:16
• I have added some explanation of how align works and how to solve your problem. May 15 '20 at 10:31
• Thanks; that makes a lot of sense; very clever. May 15 '20 at 10:32
• I've also written a copy of this in Chinese. See zhuanlan.zhihu.com/p/140775227 May 15 '20 at 12:33