11

I am using the \begin{align*} command to structure equations such that they align along the first equal sign. I want to be able to change from one equal sign to another, such that I centre equations a to w on the first equal sign, and then centre the z equation on the second equal sign. Attached is the output I'm getting. Any pointers?

\begin{align*}
a&=b\\
c&=d\\
e&=f+g+h+j=w\\
x&=y\\
z&=0\\
\end{align*}

enter image description here

I would like to be able to align the first three equations on the first equal sign and the last two equations on the second equal sign like so:

a=b
c=d
e=f+g+h+j=w
        x=y
        z=0
David Carlisle
  • 757,742
  • take a look at what can be done with alignedat. something useful might be found here: http://tex.stackexchange.com/q/200813/579 – barbara beeton Feb 09 '17 at 22:44

4 Answers4

15

Two variants:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{alignat*}{2}
a &= b\\
c &= d\\
e &= f+g+h &{}+j &= w \\
  &        &   x &= y\\
  &        &   z &= 0
\end{alignat*}

\begin{align*}
a &= b\\
c &= d\\
e &= f+g+h\begin{aligned}[t]{}+j &= w \\
                               x &= y\\
                               z &= 0
\end{aligned}
\end{align*}

\end{document} 

The {} in front of + is needed to get the spacing right, because TeX doesn't consider + a unary symbol.

enter image description here

egreg
  • 1,121,712
6

Like this?

enter image description here

Using two nested aligned environments; the outer aligned deals with the first three =s and the inner one deals with the last three =s. The negative space of \! is a correction.

Edit

Thanks to @egreg, this negative space \! is no longer needed as long as you have the latest version of amsmath installed (version 2.16a, released 2016/11/05).

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{equation*}
  \begin{aligned}
  a &= b\\
  c &= d\\
  e &= \!\begin{aligned}[t]f+g+h+j
            &= w\\
            x&=y\\
            z&=0
        \end{aligned}
  \end{aligned}
\end{equation*}

\end{document}
AboAmmar
  • 46,352
  • 4
  • 58
  • 127
3

enter image description here

\documentclass{article}

\usepackage{amsmath}

\begin{document}
ths
\begin{alignat*}{2}
a&=b\\
c&=d\\
e&=f+g+h+j&&=w\\
&        &x&=y\\
&        &z&=0\\
\end{alignat*}

or to get rid of the space
\begin{alignat*}{2}
a&=b\\
c&=d\\
e&=f+g+h+j&&=w\\
&        &\llap{$x$}&=y\\
&        &\llap{$z$}&=0\\
\end{alignat*}

\end{document}
David Carlisle
  • 757,742
2

With aligned and a horizontal correction:

\documentclass{article}
\usepackage[utf8]{inputenc}%
\usepackage{xcolor}%
\usepackage{mathtools, amssymb}
\begin{document}

\begin{align*}
  a&=b\\
  c&=d\\
  e & =f+g+h+\mspace{-\medmuskip}\begin{aligned}[t] j & =w \\
  x&=y\\
  z&=0
  \end{aligned}
\end{align*}

\end{document} 

enter image description here

Bernard
  • 271,350
  • as noted in discussion under egreg's answer the negative space is only needed for older amsmath installations not a current one. – David Carlisle Feb 09 '17 at 23:57
  • @David Carlisle: my version is 2.16a, and I observed a difference of 0.7 pt between the spacings of + g and of + j. – Bernard Feb 10 '17 at 00:24