Math & ScienceAlignment of Equation

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
Annarè
Posts: 1
Joined: Fri Nov 18, 2011 5:32 pm

Alignment of Equation

Post by Annarè »

Hello,

While I was writing mathematical functions in LaTeX I found a problem with the alignment of equations. In particular I'm using \begin{eqnarray} ... \end{eqnarray} and every time I want to start a new line use the notation ...+\nonumber\\ ...&+& ... and it seems to work. I found a problem when I have to create a newline into a mathematical function, for example:

Code: Select all

\begin{footnotesize}
\begin{eqnarray}
\hat{p} = \mathop {\arg\max }\limits_p {\mathop{{-\frac{1}{N_{0}} w^{2}\left(p_{m}^{(A)},p\right) k^{2} \int_{\tau (p_{m}^{(A)},p)}^{\tau (p_{m}^{(A)},p)+T_{p}} r^{2}(t) dt + \\
&+& \frac{2}{N_{0}} w\left(p_{m}^{(A)},p\right)\,k \int_{\tau (p_{m}^{(A)},p)}^{\tau (p_{m}^{(A)},p)+T_{p}} r^{2}(t) dt}}\nolimits}
\end{eqnarray}
\end{footnotesize}
This code gives me some troubles, (I'm working with Texmaker) and the error displayed is:
! Misplaced alignment tab character &.
There is anything I can do about it?

Thanks

Anna

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

Alignment of Equation

Post by Stefan Kottwitz »

Hi Anna,

don't use eqnarray, use an align environment of amsmath instead, see eqnarray vs. align,

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

Alignment of Equation

Post by localghost »

The eqnarray environment shouldn't be used at all any more [1]. Use the environments of the amsmath package instead.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}   % loads »amsmath«

\DeclareMathOperator*{\argmax}{\arg\max}

\begin{document}
  \begin{equation}
    \begin{aligned}
      \hat{p} &= \argmax_p -\frac{1}{N_{0}} w^{2}\left(p_{m}^{(A)},p\right) k^{2} \int_{\tau (p_{m}^{(A)},p)}^{\tau (p_{m}^{(A)},p)+T_{p}} r^{2}(t) dt + \\
      &+ \frac{2}{N_{0}} w\left(p_{m}^{(A)},p\right)\,k \int_{\tau (p_{m}^{(A)},p)}^{\tau (p_{m}^{(A)},p)+T_{p}} r^{2}(t) dt
    \end{aligned}
  \end{equation}
\end{document}
For details and other math environments refer to the package manual. Useful information about math typesetting can be found in the excellent »Math mode« document.

[1] The PracTeX Journal, TeX Users Group – Lars Madsen: Avoid eqnarray!


Best regards and welcome to the board
Thorsten
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Alignment of Equation

Post by Stefan Kottwitz »

Another alternative way would be split:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator*{\argmax}{\arg\max}
\begin{document}
\begingroup
\footnotesize
\begin{equation}
\begin{split}
      \hat{p} &= \argmax_p -\frac{1}{N_{0}} w^{2}\left(p_{m}^{(A)},p\right) k^{2} \int_{\tau (p_{m}^{(A)},p)}^{\tau (p_{m}^{(A)},p)+T_{p}} r^{2}(t) dt + \\
      &\quad+ \frac{2}{N_{0}} w\left(p_{m}^{(A)},p\right)\,k \int_{\tau (p_{m}^{(A)},p)}^{\tau (p_{m}^{(A)},p)+T_{p}} r^{2}(t) dt
\end{split}
\end{equation}
\endgroup
\end{document}
Stefan
LaTeX.org admin
Post Reply