4

I have this problem all the time: I am trying to write a very large polynomial, but when I use eqnarray it does not look very nice. Is there a way to make it look nicer ? I am using a two column template so it I have limited space.

\begin{eqnarray}\label{rsmEqu}
&& B =-0.76562-2.38354S-0.17144R+0.81956\lambda      \nonumber \\
&&-0.18059SR+0.14635S\lambda+0.0253R\lambda+0.02885S^2 \nonumber \   
\end{eqnarray}
David Carlisle
  • 757,742
sosruko
  • 423

2 Answers2

10

Your interest in prettifying the expression is most likely around the alignment. Regardless, don't use eqnarray. Rather use the capabilities of amsmath's align environment(s):

enter image description here

\documentclass[twocolumn]{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\newcommand{\noeq}{\phantom{=}{}}
\begin{document}
\section{A section}
Here is some text. Your original \verb|eqnarray|:
\begin{eqnarray}
&& B =-0.76562-2.38354S-0.17144R+0.81956\lambda      \nonumber \\
&&-0.18059SR+0.14635S\lambda+0.0253R\lambda+0.02885S^2 \nonumber \\
&&+0.00815R^2+0.00332\lambda^2-0.00112SR\lambda+0.01041S^2R\nonumber \\
&&-0.00665S^2\lambda+0.000005SR^2+0.00016S\lambda^2 \nonumber \\
&&-0.000173R^2\lambda+0.00317S^3+0.000006R^3\nonumber \\
&&-0.00017\lambda^3
\end{eqnarray}
Here is an \verb|align| version:
\begin{align}
B &= -0.76562-2.38354S-0.17144R+0.81956\lambda \nonumber \\
  &\noeq -0.18059SR+0.14635S\lambda+0.0253R\lambda \nonumber \\
  &\noeq +0.02885S^2+0.00815R^2+0.00332\lambda^2 \nonumber \\
  &\noeq -0.00112SR\lambda+0.01041S^2R-0.00665S^2\lambda \nonumber \\
  &\noeq +0.000005SR^2+0.00016S\lambda^2-0.000173R^2\lambda \nonumber \\
  &\noeq +0.00317S^3+0.000006R^3-0.00017\lambda^3
\end{align}
\lipsum[1-3]
\end{document}

As a motivation, see \eqnarray vs \align, where you will find additional reference to not using eqnarray.

Moriambar
  • 11,466
Werner
  • 603,163
6

I would recommend using the alignat environment instead as the alignment of the binary operators makes the equation easier to read:

enter image description here

Here is the extended example from Werner's solution using alignat:

enter image description here

Notes:

  • Similar to the align environment, the alignat provides multiple rl alignments but without the spacing in between the pairs of rl equations. The && was necessary to make the following column left aligned (and skip past the right aligned column).
  • The {} before the plus and minus was to ensure that they were treated as binary operators.

Code:

\documentclass{article}
\usepackage{amsmath}

\begin{document} \noindent Example from MWE: \begin{alignat}{6} B &= &&{}-0.76562 &&{}-2.38354S &&{}-0.17144R &&{}+ 0.81956\lambda \ & &&{}-0.18059SR &&{}+0.14635S\lambda &&{}+0.0253R\lambda &&{}+ 0.02885S^2 \end{alignat} Extended example from Werner's solution: \begin{alignat}{6} B &= &&{}-0.76562 &&{}-2.38354S &&{}-0.17144R &&{}+0.81956\lambda \ & &&{}-0.18059SR &&{}+0.14635S\lambda &&{}+0.0253R\lambda &&{}+0.02885S^2 \ & &&{}+0.00815R^2 &&{}+0.00332\lambda^2 &&{}-0.00112SR\lambda &&{}+0.01041S^2R\ & &&{}-0.00665S^2\lambda &&{}+0.000005SR^2 &&{}+0.00016S\lambda^2 &&{}-0.000173R^2\lambda \ & &&{}+0.00317S^3 &&{}+0.000006R^3 &&{}-0.00017\lambda^3 \end{alignat} \end{document}

Peter Grill
  • 223,288