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.

Consider this expression:

enter image description here

How can I code this in LaTeX such that everything is aligned at the "=" sign such that the distance to the left and the right of the "=" sign at each line is the same as the distance to the other "=" which aren't in some separate column to which everything has to align to.

(Using for example eqnarray doesn't help, since in this case I can align everything at "=", but the distance to the left and the right is way off.)

share|improve this question

1 Answer 1

up vote 10 down vote accepted

You are perfectly correct in saying that eqnarray is not the right tool here. The amsmath package provides several environments for displayed equations with correct spacing. (Extra features are available from the mathtools package.) In your example align* is the relevant construct to use (remove the * if you want equation numbers):

Sample output

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align*}
  x_1+x_2 &= (-p + i \sqrt{q-p^2}) + (-p - i \sqrt{q-p^2}) = - 2p,\\
  x_1\cdot x_2 &= (-p + i \sqrt{q-p^2}) \cdot (-p - i \sqrt{q-p^2})
  = (-p)^2 - (i \sqrt{q-p^2})^2 \\
  &= q.
\end{align*}

\end{document}

Alignment points are specified by &, newlines by \\.

share|improve this answer
    
perfect! thanks. –  user10324 Jun 21 at 10:12
1  
"eqnarray is no the right tool here" ... It's never the right tool. :) –  Svend Tveskæg Jun 22 at 11:50

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.