2

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

\begin{eqnarray*}
\bar{x}& = & \frac{1}{n} \sum_{i=1}^n x_i\\
    & = & \frac{45+60+...+53+65}{10}\\
    & = &\frac{284}{5}\\
\end{eqnarray*}
\subsection{Another one}
Some text and other tings...
\begin{eqnarray*}
    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)\\
\end{eqnarray*}

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?

2

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

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

\newlength\mylena
% save longest string of second equation block
\newcommand\longstring{\frac{1}{9}((45-57,2)^2+(60-57,2)^2+\dots+(65-57,2)^2)}
\settowidth\mylena{$\displaystyle\longstring$} % measure width of this string

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

\begin{document}

\begin{align*}
\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{\mylenb}{}
        &= \parbox{\mylena}{$\displaystyle\frac{284}{5}$}\\
\end{align*}


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.