Math & ScienceEqnarray: numbering last line only.

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
haaj86
Posts: 21
Joined: Mon Apr 06, 2009 11:18 pm

Eqnarray: numbering last line only.

Post by haaj86 »

Hi, how can I number the last line only of an equation array I know that if I write the eqnarray command like this \begin{eqnarray*} all the equation will not be numbered, and if I remove * all the lines in the array will be numbered, but I just want the last line to be numbered.
Thank you

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Eqnarray: numbering last line only.

Post by Stefan Kottwitz »

Hi,

don't use eqnarray, I recommend align instead, for reasons see eqnarray vs. align.
You can suppress the number of certain lines inside the align environment if you write \notag before \\, see amsmath user's guide.

Stefan
LaTeX.org admin
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Eqnarray: numbering last line only.

Post by localghost »

You should not use the eqnarray environment any more [1]. Take the align environment from amsmath and prevent selected lines from numbering.

Code: Select all

\begin{align}
  (a+b)^2&=a^2+2ab+b^2 \nonumber \\
  (a-b)^2&=a^2-2ab+b^2 \nonumber \\
  (a+b)(a-b)&=a^2-b^2
\end{align}
Instead of \nonumber you can also use the \notag command.

[1] The PracTeX Journal - Lars Madsen: Avoid eqnarray!


Best regards
Thorsten¹
haaj86
Posts: 21
Joined: Mon Apr 06, 2009 11:18 pm

Eqnarray: numbering last line only.

Post by haaj86 »

Thank you so much guys, its working. The problem I had with using align was when I create three columns. The third column becomes aligned to the right. For example is if I use your previous code like this:

Code: Select all

\begin{align}
  (a+b)^2&=&a^2+2ab+b^2 \nonumber \\
  (a-b)^2&=&a^2-2ab+b^2 \\
  (a+b)(a-b)&=&a^2-b^2 \nonumber
\end{align}
Then the third column will be aligned to the right and I get a gap between the equal sign and the right hand side expression. I am guessing that it has to do with entering some option in \begin[option]{align}, but I am new to Latex so I really don't know. However, I didn't get this problem with using eqnarray.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Re: Eqnarray: numbering last line only.

Post by Stefan Kottwitz »

Hi,

the syntax of align is slightly different to that of eqnarray. In eqnarray the & is a column separator, in align the & marks alignment points. That's why you just need one & before the relation symbol. align generates two columns, eqnarray three.

If you want to align at several places, using several & in align, consider to use the alignat environment instead.

Stefan
LaTeX.org admin
haaj86
Posts: 21
Joined: Mon Apr 06, 2009 11:18 pm

Re: Eqnarray: numbering last line only.

Post by haaj86 »

Thank you for all your help.
Post Reply