3

I'd like to make equations that align like this:

x = y x 
    z
  = a x
    b

Here's an MWE:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{align*} 
x &=  &y \times  \\
  &   &z         \\
  &=  &a \times  \\
  &   &b  
\end{align*}

\end{document}

However, it produces this:

right aligned equations

Could you please suggest how I can align as I wish?

Thanks A

  • Thanks, Greg. My observation on this forum: I used Latex in grad school, which I completed about 25 years ago. At the time, a distressingly large amount of PhD student discussion was devoted to solving Latex problems -- and disturbingly little to computer science. This was particularly true when actually writing theses. I dropped Latex shortly after graduating, and only recently picked it up again. These days, because I get great typesetting help here, I can spend my time talking to colleagues about science. It's a real boon. – Arthur Goldberg Dec 18 '15 at 22:25
  • Yes, 25 years ago we were basically on our own: the resources were TUGboat and TeXhax, besides the manuals. There's much more help available nowadays, but also much more features. A place like this is very useful because each one can throw in their expertise in already solved problems and knowledge of the hundreds of packages. – egreg Dec 18 '15 at 22:34
4

You have too many &'s. For this kind of alignment you need a “special trick”:

\begin{align*}
x ={} & y \times{} \\
      & z \\
  ={} & a \times{} \\
      & b
\end{align*}

The purpose of the {} (empty subformulas) is to make the right spacing around the relation and operation symbols.

An empty subformula is implicitly inserted in the even numbered columns of an align (or align*) environment. Even numbered columns have left alignment, whereas odd numbered ones have right alignment.

Another way (but more complicated) is

\begin{align*}
x &= y \times{} \\
  &\mathrel{\hphantom{=}} z \\
  &= a \times{} \\
  &\mathrel{\hphantom{=}} b
\end{align*}

The {} after the binary operation symbol is necessary anyway, as the following example shows.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

Good example of the alignment you want:
\begin{align*}
x ={} & y \times{} \\
      & z \\
  ={} & a \times{} \\
      & b
\end{align*}
The following is equivalent to the above one
\begin{align*}
x &= y \times{} \\
  &\mathrel{\hphantom{=}} z \\
  &= a \times{} \\
  &\mathrel{\hphantom{=}} b
\end{align*}
Compare the spacing around $\times$ in the following example:
\begin{align*}
x ={} & y \times \\
      & z \\
  ={} & a \times \\
      & b
\end{align*}

\end{document}

enter image description here

| improve this answer | |
0

Here are two ways with TABstacks, neither of which requiring the "special trick" of empty subgroup. In the first case, which uses the OP's proposed alignment tabs, it does require the equivalent "special trick" of \TABbinary, which adds an empty subgroup at the beginning and end each cell. Alternately, the tabstackengine version of align for a stack requires no such trick.

\documentclass{article}
\usepackage{tabstackengine}
\setstacktabulargap{0pt}
\stackMath
\begin{document}
\[ 
\TABbinary
\tabularCenterstack{rcl}{
x &=  &y \times  \\
  &   &z         \\
  &=  &a \times  \\
  &   &b 
} 
\]
\[ 
\alignCenterstack{
x =  &y \times  \\
     &z         \\
  =  &a \times  \\
     &b 
} 
\]
\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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