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.

The following piece of code

\begin{eqnarray*}
\expval[\mathcal{N}] &= \frac{\rho_0}{\rho_1} ~, &
\var(\mathcal{N}) &= \frac{\rho_0}{\rho_1} + 0.280 \, \frac{\rho_0^2}{\rho_1^2} ~, \\
\expval[\mathcal{L}] &= \frac{\rho_0}{2 \rho_1^{3/2}} ~, &
\var(\mathcal{L}) &= \frac{\rho_0}{\pi \rho_1^2} + 0.147 \, \frac{\rho_0^2}{\rho_1^3} ~.
\end{eqnarray*}

gives the following error.

! Missing $ inserted. <inserted text> 
                $ l.34 \var(\mathcal{N}) &= \frac{\rho_0}{\rho_1}
                                                + 0.280 \, \frac{\rho_0^2}{\...

I have defined \expval and \var in the document preamble as follows.

\newcommand{\expval}{\mathbb{E}}
\newcommand{\var}{\mathrm{Var}}

Just wondering what the issue could be.

share|improve this question
6  
The use of eqnarray is outdated and should be replaced by something more advanced; offered in the form of align from amsmath. Moreover, eqnarray only allows a singular alignment, while you're attempting to align more than one equation (further motivating the use of align). –  Werner Mar 29 '12 at 6:53
    
@Werner, ahh. I had ever only used eqnarray once, so didn't know it had that limitation! Thank you! –  zeroth Mar 29 '12 at 7:00
add comment

3 Answers

up vote 7 down vote accepted

You should rather use align* from amsmath:

enter image description here

\documentclass{article}
\usepackage{amsfonts}% http://ctan.org/pkg/amsfonts
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\newcommand{\expval}{\mathbb{E}}
\newcommand{\var}{\mathrm{Var}}
\begin{document}
\begin{align*}
\expval[\mathcal{N}] &= \frac{\rho_0}{\rho_1} ~, &
\var(\mathcal{N}) &= \frac{\rho_0}{\rho_1} + 0.280 \, \frac{\rho_0^2}{\rho_1^2} ~, \\
\expval[\mathcal{L}] &= \frac{\rho_0}{2 \rho_1^{3/2}} ~, &
\var(\mathcal{L}) &= \frac{\rho_0}{\pi \rho_1^2} + 0.147 \, \frac{\rho_0^2}{\rho_1^3} ~.
\end{align*}
\end{document}

See more discussion on this topic from \eqnarray vs \align.

share|improve this answer
add comment

I am not too sure about the error in eqnarray however, first I suggest you read:

Eqnarray vs align

and realize that eqnarray is really bad for you! :)

Then you should notice that whenever you need to define a function (or operator) it is best to do so by \DeclareMathOperator. That will yield better spacing for you.

Also better let TeX do the spacing. Just my opinion. :)

So in effect you can do:

\documentclass{article}
\usepackage{amsmath,amsfonts}
\DeclareMathOperator{\expval}{\mathbb{E}}
\DeclareMathOperator{\var}{Var}
\begin{document}
\begin{align*}
  \expval[\mathcal{N}] &= \frac{\rho_0}{\rho_1}        , &
  \var(\mathcal{N})    &= \frac{\rho_0}{\rho_1}+0.280 \frac{\rho_0^2}{\rho_1^2}, 
  \\ % Next line
  \expval[\mathcal{L}] &= \frac{\rho_0}{2 \rho_1^{3/2}} , &
  \var(\mathcal{L})    &= \frac{\rho_0}{\pi \rho_1^2} + 0.147 \frac{\rho_0^2}{\rho_1^3}.
\end{align*}

\end{document}
share|improve this answer
    
Got it, thanks :) –  Ali Mar 29 '12 at 7:07
add comment

Inside eqnarray you use 3 & this is the problem.

If you want align at 3 places use alignat tag, see below:

\documentclass{minimal}
\usepackage{amsmath,amssymb}

\newcommand{\expval}{\mathbb{E}}
\newcommand{\var}{\mathrm{Var}}

\begin{document}

\begin{alignat*}{3}
\expval[\mathcal{N}] &= \frac{\rho_0}{\rho_1} ~, &
\var(\mathcal{N}) &= \frac{\rho_0}{\rho_1} + 0.280 \, \frac{\rho_0^2}{\rho_1^2} ~, \\
\expval[\mathcal{L}] &= \frac{\rho_0}{2 \rho_1^{3/2}} ~, &
\var(\mathcal{L}) &= \frac{\rho_0}{\pi \rho_1^2} + 0.147 \,
\frac{\rho_0^2}{\rho_1^3} ~.
\end{alignat*}

\end{document}
share|improve this answer
add comment

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.