11

How do I produce the following in align environment?

\begin{eqnarray*}& & abcd \\
&=& defg\\
&=& hijk
\end{eqnarray*}

I try

\begin{align*}&  abcd \\
&= defg\\
&= hijk
\end{align*}

But the result is not what I wanted.

David Carlisle
  • 757,742
TCL
  • 1,140

6 Answers6

17

To avoid guessing about the space, you can use

\begin{align*}
  &\mathrel{\phantom{=}} abcd \\
  &= defg\\
  &= hijk
\end{align*}
David Carlisle
  • 757,742
11

Here you've got the fifth solution, which shows you that what you want to do is indeed slightly tricky in align.

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{align*}
     & abcd \\
 ={} & defg \\
 ={} & hijk 
\end{align*}
\end{document}

The trick: If you have the = in the left column, then you need to put something after it to get correct spacing.

David Carlisle
  • 757,742
Hendrik Vogt
  • 37,935
5

This is sort of cheating, but in your example document, the following also works:

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

 \begin{align*}
    a&bcd \\
  = d&efg \\
  = h&ijk
 \end{align*}

\end{document}

Why? Because I know that a, d, and h all have the same width. This trick is surprisingly generalizable.

Another solution gives virtually identical results as eqnarray:

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

 \begin{equation*}
  \begin{aligned}
   & & abcd \\
   &=& defg \\
   &=& hijk
  \end{aligned}
 \end{equation*}

\end{document}

This works because the aligned subenvironment (which must be enclosed in a larger equation or the like) shrinks to fit its contents exactly, and separates columns by a minimal amount. You can tweak this amount by redefining \minalignsep:

\renewcommand*{\minalignsep}{2em} % 10pt by default

as in this answer: Could I change the default column sep of `aligned` from \quad to \qquad globally?.

Personally, I would go with Hendrik Vogt's method, though.

David Carlisle
  • 757,742
Ryan Reich
  • 37,958
4
\begin{align*}
  &\quad\, abcd \\
  &=       defg \\
  &=       hijk
\end{align*}
David Carlisle
  • 757,742
4

in this special case you can use the order =&, which should be by default the other way round:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{align*}
  &\; abcd \\
 =&\; defg\\
 =&\; hijk 
\end{align*}

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

A quick and dirty solution would be

\begin{align*}&abcd \\
=\ &defg\\
=\ &hijk
\end{align*}

Obviously, you can increase the whitespace as you might wish.

David Carlisle
  • 757,742
percusse
  • 157,807