TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question
    
take a look at what can be done with alignedat. something useful might be found here: tex.stackexchange.com/q/200813/579 – barbara beeton 12 hours ago

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

share|improve this answer
    
Umm, that {} in the second example gives more space than actually required. – AboAmmar 11 hours ago
    
@AboAmmar Really? – egreg 11 hours ago
    
Yes, the first one is exact but the second has more space between h and +. To make sure, add a third line e &= f+g+h+j=w \\% and compare. – AboAmmar 11 hours ago
1  
@AboAmmar Not in my output. If you get more space, it's time to update your TeX distribution. Quite recently, amsmath has been updated not to add \, in this situation. Ensure to have version 2.16a, released 2016/11/05. – egreg 11 hours ago
1  
@egreg excellent update to amsmath do you know where it came from? – David Carlisle 11 hours ago

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}
share|improve this answer

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}
share|improve this answer

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

share|improve this answer
    
as noted in discussion under egreg's answer the negative space is only needed for older amsmath installations not a current one. – David Carlisle 11 hours ago
    
@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 10 hours ago

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.