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.

I would like to get a nonstandard alignment in the following code:

\begin{align}
  \text{First left hand side}  & = \text{First right hand side} \\
  \text{Second left hand side} & = \text{Second right hand side} \\
    & = \text{Loooooooooooooooooooooooooooooooong expanded right hand side}
\end{align}

where the last line should not be aligned with the first two lines. I know that I could split the last line to form multiple right hand sides, but I would rather avoid it, as it would fill four equations in my case.

I found an evil way of doing it by nesting align and gather:

\begin{gather}
  \begin{align}
    \text{First left hand side}  & = \text{First right hand side} \\ %% \label{} does not work here
    \text{Second left hand side} & = \text{Second right hand side}
  \end{align}\\
 = \text{Loooooooooooooooooooooooooooooooong expanded right hand side} \label{eq3}
\end{gather}

but alas, while this gives the visual output I want, I can not use labels to refer to the equations within the align.

I also don't want to place & somewhere in the middle of the third line due to spacing issues, and because it is a fragile way of doing that.

So how can I type that

  1. the first and second line align at =
  2. the third line is not aligned ot the first two lines (preferably flushed right)
  3. all three lines are numbered, and can be referenced
  4. all three lines are in one equation group (for the semantics and the spacing)?
share|improve this question
    
@cmhughes without the & the last line becomes a left hand side, pushing everything right. The last line shall be really that long so it needs both the space of the left and right hand sides of the first two lines. –  mafp Nov 26 '12 at 17:27
    
indeed, I realized this soon after posting it- deleted :) –  cmhughes Nov 26 '12 at 17:29
add comment

4 Answers 4

up vote 10 down vote accepted

A bit of a low-level trick:

\documentclass{article}

\usepackage{amsmath}

\begin{document}
\begin{align}
  \text{First left hand side}  & = \text{First right hand side} \\
  \text{Second left hand side} & = \text{Second right hand side} \\
  \omit \span  = \text{Loooooooooooooooooooooooooooooooong expanded right hand side}
\end{align}
\end{document}

enter image description here

The above left aligns the last line. If you want the last line to be flush right, use (note order of the expression and \omit\span has changed)

\begin{align}
  \text{First left hand side}  & = \text{First right hand side} \\
  \text{Second left hand side} & = \text{Second right hand side} \\
  = \text{ expanded right hand side} \span \omit
\end{align}

which gives

enter image description here

share|improve this answer
    
This one did it for me, thanks. –  mafp Nov 26 '12 at 20:51
    
Can you explain the meaning of \omit and \span? –  Ari Brodsky Dec 6 '12 at 10:08
add comment

This might be the trick you need:

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

\makeatletter
\newcommand{\unalign}[1]{%
  \ifmeasuring@ \else
    \makebox[\ifcase 1\maxcolumn@widths \fi][l]{$\displaystyle#1$}
  \fi
}
\makeatother

\begin{align}
  \text{First left hand side}  & = \text{First right hand side} \\
  \text{Second left hand side} & = \text{Second right hand side} \\
  \unalign{= \text{Long expanded right hand side}}
\end{align}
\end{document}

The argument of \unalign is ignored for the measurements and then typeset in a box apparently as wide as the left hand sides of the other equations. Of course this is not completely safe, if the argument is very long, but for a one shot case it might be sufficient.

enter image description here

If you want the unaligned line to be flush with the widest right hand side, change the definition into

\documentclass{amsart}
\begin{document}

\makeatletter
\newcommand{\unalign}[1]{%
  \ifmeasuring@ \else
    &\makebox[\ifcase2\maxcolumn@widths \fi][r]{$\displaystyle#1$}
  \fi
}
\makeatother

\begin{align}
  \text{First left hand side}  & = \text{First right hand side} \\
  \text{Second left hand side} & = \text{Second right hand side} \\
  \unalign{= \text{Long expanded right hand side}}
\end{align}
\end{document}

enter image description here

share|improve this answer
    
Neat, thank you. I chose Aditya's solution because the third line is really long in my real use case. But I put your solution under my belt for future application :-) –  mafp Nov 26 '12 at 20:59
add comment

A bit quick and dirty, but what about

\begin{align}
    \text{First left hand side}  & = \text{First right hand side} \\
    \text{Second left hand side} & = \text{Second right hand side} \\
    = \text{Loooooooooooooooooooo}&\text{oooooooooooong expanded right hand side}
\end{align}
share|improve this answer
    
This is the way I used to do it, but as I wrote: I also don't want to place & somewhere in the middle of the third line due to spacing issues, and because it is a fragile way of doing that. –  mafp Nov 26 '12 at 17:40
    
@mafp Oh sorry, should read questions carefully... –  Alex Nov 26 '12 at 17:42
add comment

Probably not good style to answer my question after having accepted another answer, but I have two more solutions.

The first solution (from Ulrich Diez) makes the labels within align within gather work:

\makeatletter
\newcommand*\savedf{\@bsphack\global\let\sdf\df@label\@esphack}
\newcommand*\restoredf{\@bsphack\global\let\df@label\sdf\@esphack}
\newcommand*\mylabel{\restoredf\label}
\makeatother
...
\begin{gather}
  \savedf
  \begin{align}
    \text{First left hand side}  & = \text{First right hand side}
      \mylabel{eq:e1} \\
    \text{Second left hand side} & = \text{Second right hand side}
      \mylabel{eq:e2}
  \end{align} \restoredf \\
  = \text{Loooooooooooooooooooooooooooooooong expanded right hand side}
     \notag \\
  = \text{Another line} \label{eq:e3}
\end{gather}
\eqref{eq:e1},\eqref{eq:e2},\eqref{eq:e3}

It is hackish, but it works, and it gives a different layout than the other solutions.

The second solution uses the mathtools package, and its \MoveEqLeft command:

\usepackage{mathtools}
...
\begin{align}
  \text{First left hand side}  & = \text{First right hand side} \\
  \text{Second left hand side} & = \text{Second right hand side} \\
  \MoveEqLeft[9] = \text{Loooooooooooooooooooooooooooooooong expanded right hand side}
\end{align}

This seems most elegant, but requires hand tuning the shift space, here 9em. The \MoveEqLeft command sets an alignment point, and then shifts the remaining material by the specified amount of em's to the left. Works even with negative numbers, i.e., shifting to the right.

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