3

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.

  • 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
7

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.

| improve this answer | |
3

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}
| improve this answer | |
1

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}
| improve this answer | |

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.