Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}

output

share|improve this question
1  
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. –  egreg Jan 14 '12 at 11:46
1  
Does &\phantom{=} work as well? –  celtschk 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. –  Federico Poloni Jan 14 '12 at 22:36
add comment

2 Answers

up vote 5 down vote accepted

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.

share|improve this answer
1  
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 =. –  egreg 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? –  Ryan Reich Jan 14 '12 at 15:58
1  
Programmers' decision to define a uniform syntax? :) –  egreg 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. –  barbara beeton Jan 14 '12 at 20:22
    
@barbarabeeton I don't think it depends on tex.web; it's just a good way to implement templates for \halign. Conversely, Lamport's implementation of eqalign is quite bad, as the spacing around the relation is just wrong. –  egreg Jan 14 '12 at 20:27
show 1 more comment

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.

share|improve this answer
    
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. –  Federico Poloni 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. –  Federico Poloni Jan 14 '12 at 22:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.