[texhax] Problem with eqnarray

Sukomal Modak SUKOMAL at csiberkeley.com
Sun Apr 10 21:34:30 CEST 2005


Dear Modhumita,

> > \begin{eqnarray}
> >   f(x,y,z) & = & P \times \\
> >   \exp \bigl[ -\bigl( \frac{ \cos \theta \cos \phi (x - \mu_x) \\
> >                             + \sin \theta (y - \mu_y) \\
> >                    - \cos \theta \sin \phi (z -
> \mu_z)}{A_x} \bigr)^2 \\
> >             -\bigl(\frac{ \sin \theta \cos \phi (x - \mu_x) \\
> >                         + \cos \theta (y - \mu_y) \\
> >                   + \sin \theta \sin \phi (z - \mu_z)}{A_y}
> \bigr)^2 \\
> >   -\bigl( \frac{\sin \phi (x - \mu_x) + \cos \phi (z - \mu_z)}{A_z} 
> > \bigr)^2 \bigr] \end{eqnarray}

You can try any of the following two options:

\usepackage[?]{amsmath}

\begin{eqnarray}
  f(x,y,z) = P \times \exp \Bigg[
      &-&\left(\frac{ \cos \theta \cos \phi (x - \mu_x)
                    +\sin \theta (y - \mu_y)
                    -\cos \theta \sin \phi (z - \mu_z)}
                   {A_x}
         \right)^2 \nonumber \\
      &-&\left(\frac{ \sin \theta \cos \phi (x - \mu_x)
                    +\cos \theta (y - \mu_y)
                    +\sin \theta \sin \phi (z - \mu_z)}
                   {A_y}
         \right)^2 \nonumber \\
      &-&\left(\frac{ \sin \phi (x - \mu_x)
                    +\cos \phi (z - \mu_z)}
                   {A_z}
         \right)^2 \Bigg]
\end{eqnarray}

\begin{align}
  f(x,y,z) = P \times \exp \Bigg[
      &-\left(\frac{ \cos \theta \cos \phi (x - \mu_x)
                    +\sin \theta (y - \mu_y)
                    -\cos \theta \sin \phi (z - \mu_z)}{A_x}
        \right)^2 \nonumber\\
      &-\left(\frac{ \sin \theta \cos \phi (x - \mu_x)
                    +\cos \theta (y - \mu_y)
                    +\sin \theta \sin \phi (z - \mu_z)}{A_y}
        \right)^2 \nonumber\\
      &-\left(\frac{ \sin \phi (x - \mu_x)
                    +\cos \phi (z - \mu_z)}{A_z}
        \right)^2 \Bigg] \nonumber
\end{align}

For the second option, you need to use the amsmath package with
\usepackage[?]{amsmath}. You can use multiple package as you need. For
example, AASTeX style package can also be used. I hope amsmath and
aastex are compatible (I have no real experience in using both of them
together).

If you include both the equations, you will be able to see the
difference in spacings before the minus signs. For the equation typeset
with align environment, the spacings are much better than that for plain
eqnarray. This is what Morten and Robin mentioned earlier.

You do not need to put \\ after every line in your input tex file in any
of the equation environment. You need to put this only where you want a
line break in the displayed equation in the output. The use of extra \\
after the group for \frac started with { and before closing the group
with } is confusing. Is it a real line break or a line break within the
numerator of frac? This is what Robin pointed out.

You can use \left( and \right) pair, or similar pairs, across lines.
That is why you were getting error messages. If you open an adjustable
size parenthesis with \left( and if you have to break the line before
closing it with \right), you can use a dummy closing using \right. . For
example:

\left(   blah blah \right. \\
\left.   blah blah \right)

However, sometimes this creates a problem in determining the appropriate
size of the parenthesis automatically. In such case you can use \bigl(,
\big(, \bigg(, \Big(, \Bigg(, etc. This is also mentioned by Morten.

You do not need any escape character to get [ bracket. A simple [ or
\left[ is good enough. \[ has a special meaning. However, you need \{ to
get braces in the equation, as { alone has a special meaning. 

You should also consider giving extra spacing after \theta and \phi
using \, or \; to beautify the equations.

I suggest that you read the amsmath documentation. This will pay you big
time.

Hope this helps.

Regards,
--
Sukomal Modak

=================================
Sukomal Modak, Ph.D.

Structural Engineer (R&D)
Computers and Structures, Inc.
1995 University Ave., Suite 540
Berkeley, CA 94704

Tel: (510) 845-2177 (x 234)
Fax: (510) 845-4096
=================================



More information about the texhax mailing list