I am using multiple eqnarray* in one document, but the align doesnt look nice:

\bar{x}& = & \frac{1}{n} \sum_{i=1}^n x_i\\
    & = & \frac{45+60+...+53+65}{10}\\
    & = &\frac{284}{5}\\
\subsection{Another one}
Some text and other tings...
    s^2 & = & \frac{1}{n-1} \sum_{i=1}^n (x_i - \bar{x})^2\\
    & = & \frac{1}{9} ((45-57,2)^2+(60-57,2)^2+\dots+(65-57,2)^2)\\

If you look at the result, you can see that not all the equal signs align equally. The grouping with eqnarray* works, but because we have to insert some other stuff (like subsections), we can't continue the eqnarray* to force all equal signs from both eqnarray* to align the same way. How can we do this?


1 Answer 1


I can think of no convincing reason for aligning unrelated equation structures across sectioning units of the document. However, if you absolutely, positively must perform such an alignment, it can be achieved, but only through manual intervention. In the solution provided below, parts of the upper equation are encased in \parbox statements, where the widths of the boxes are determined by the longest items to the left and right of the = symbols in the lower equation.

As others have already remarked: Don't use eqnarray -- it's very badly deprecated, and far-superior alternatives are readily available. Also, don't type ...; use \dots instead.

enter image description here

\usepackage{amsmath} % for 'align*' environment

% save longest string of second equation block
\settowidth\mylena{$\displaystyle\longstring$} % measure width of this string

\settowidth\mylenb{$\displaystyle s^2$} % measure width of this string too


\parbox{\mylenb}{\hfill$\displaystyle\bar{x}$} % right-align the material
        &= \frac{1}{n} \sum_{i=1}^n x_i\\
        &= \frac{45+60+\dots +53+65}{10}\\
        &= \parbox{\mylena}{$\displaystyle\frac{284}{5}$}\\

\subsection{Another one}
Some text and other things \dots 
   s^2 &= \frac{1}{n-1} \sum_{i=1}^n (x_i-\bar{x})^2\\
       &= \longstring\\

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .