2

I'm trying to align two equations using eqnarray.

Sample:

\documentclass{article}
\begin{document}

\subsubsection*{\begin{center}Variance equations\end{center}}
\begin{eqnarray}
\mu = \tfrac{1}{NM}\sum\limits_{x=1}^N\sum\limits_{y=1}^MA(y,x)\nonumber\\
varTot = \tfrac{1}{NM}\sum\limits_{x=1}^N\sum\limits_{y=1}^M(A(y,x)-\mu)^2
\end{eqnarray}
\end{document}

The task description specifically states that I should use eqnarray.

Image of what it should look like (I achieved this earlier by using two equation environments):

enter image description here

  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Martin Schröder Nov 17 '14 at 0:58
  • 2
    If using eqnarray` you need &=& but really it is better not to use that and use align from amsmath. Also don't use math italic for multi-letter identifiers, use \mathit{varTot} so it looks like a word not a product of variables, and \begin{center in a section title is so wrong:-) just use plain text and specify section formatting elsewhere (apart from looking weird, it will mess up the table of contents) – David Carlisle Nov 17 '14 at 1:08
  • 2
    you don't need \limits (limits layout is automatic in display math for \sum) – David Carlisle Nov 17 '14 at 1:09
  • Thanks for the tips mate! Adding &=& got it working. I don't understand what you mean by 'use \mathit{varTot}' I see no difference. – Lightvvind Nov 17 '14 at 1:14
  • Make a zoom and you'll see differences: small spaces are added between letters if you don't use \mathit; they correspond to the side bearings, that are necessary e.g. in case of exponents or indices. – Bernard Nov 17 '14 at 1:19
4

Here are two solutions, first with eqnarray, then with align (an environment provided by the amsmath package). Note the absurdly large amount of space around the = symbols when using eqnarray -- it's one of the reasons why eqnarray is considered badly deprecated these days and really shouldn't be used anymore.

Incidentally, since both eqnarray and align set their material in \displaystyle math mode, \limits is on by default and needn't be specified.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\setlength\textwidth{3in} % just for this example
\begin{document}

\subsubsection*{With \ttfamily eqnarray}
\begin{eqnarray}
\mu &=& \tfrac{1}{NM}\sum_{x=1}^N\sum_{y=1}^MA(y,x)\nonumber\\
\mathrm{varTot} &=& \tfrac{1}{NM}\sum_{x=1}^N\sum_{y=1}^M(A(y,x)-\mu)^2
\end{eqnarray}

\subsubsection*{With \ttfamily align}
\begin{align}
\mu &= \tfrac{1}{NM}\sum_{x=1}^N\sum_{y=1}^MA(y,x)\nonumber\\
\mathrm{varTot} &= \tfrac{1}{NM}\sum_{x=1}^N\sum_{y=1}^M(A(y,x)-\mu)^2
\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.