105

I wonder how to label each equation in align environment? For example

\begin{align} \label{eq:lnnonspbb}
\lambda_i + \mu_i = 0 \\
\mu_i \xi_i = 0 \\
\lambda_i [y_i( w^T x_i + b) - 1 + \xi_i] = 0
\end{align} 

only label the first equation and only the first equation can be referred later.

glennsl
  • 28,186
  • 12
  • 57
  • 75
Tim
  • 1
  • 141
  • 372
  • 590

6 Answers6

130

You can label each line separately, in your case:

\begin{align}
  \lambda_i + \mu_i = 0 \label{eq:1}\\
  \mu_i \xi_i = 0 \label{eq:2}\\
  \lambda_i [y_i( w^T x_i + b) - 1 + \xi_i] = 0 \label{eq:3}
\end{align} 

Note that this only works for AMS environments that are designed for multiple equations (as opposed to multiline single equations).

Martijn
  • 5,471
  • 4
  • 37
  • 50
  • 6
    What do you mean by "AMS environments that are designed for multiple equations (as opposed to multiline single equations)"? – jvriesem Feb 05 '16 at 18:04
  • 7
    @jvriesem: the environment `align` is meant for multiple equations. Each equation will receive a number. If you use an `equation` environment, and put an `aligned` environment inside it, the whole block is considered as one equation, and will receive one number. Putting multiple `\label`s inside it will result in errors – Martijn Feb 06 '16 at 10:50
18

Usually my align environments are set up like

\begin{align} 
  \label{eqn1}
  \lambda_i + \mu_i = 0 \\
  \label{eqn2}
  \mu_i \xi_i = 0 \\
  \label{eqn3}
  \lambda_i [y_i( w^T x_i + b) - 1 + \xi_i] = 0
\end{align} 

The \label command should be placed in the line you want to reference, the placement in the line does not matter. I prefer to place it at the beginning at the line (as a sort of description) while others place them at the end.

midtiby
  • 14,550
  • 6
  • 34
  • 43
10

Within the environment align from the package amsmath it is possible to combine the use of \label and \tag for each equation or line. For example, the code:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
Write
\begin{align}
x+y\label{eq:eq1}\tag{Aa}\\
x+z\label{eq:eq2}\tag{Bb}\\
y-z\label{eq:eq3}\tag{Cc}\\
y-2z\nonumber
\end{align}
then cite \eqref{eq:eq1} and \eqref{eq:eq2} or \eqref{eq:eq3} separately.
\end{document}

produces:

screenshot of output

MattAllegro
  • 6,455
  • 5
  • 45
  • 52
9

\tag also works in align*. Example:

\begin{align*}
  a(x)^{2} &= bx\tag{1}\\ 
  a(x)^{2} &= b\tag{2}\\ 
  ax &= b\tag{3}\\ 
  a(x)^{2}+bx &= c\tag{4}\\ 
  a(x)^{2}+c &= bx\tag{5}\\ 
  a(x)^{2} &= bx+c\tag{6}\\ \\ 
  Where\quad a, b, c \, \in N
\end{align*}

Output:

PDF output for \tag example

MattAllegro
  • 6,455
  • 5
  • 45
  • 52
Kay Pen
  • 91
  • 1
  • 2
6

like this

\begin{align} 

x_{\rm L} & = L \int{\cos\theta\left(\xi\right) d\xi}, \label{eq_1} \\\\

y_{\rm L} & = L \int{\sin\theta\left(\xi\right) d\xi}, \nonumber

\end{align}
MathieuF
  • 3,130
  • 5
  • 31
  • 34
Mathieu
  • 61
  • 1
  • 1
3

The answers seem a bit dated, they don't work for me. What did work was

\begin{align}
1+1=2     \tag{xyz}
\end{align}

reference