How to label each equation in align environment?
Asked Answered
P

6

107

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.

Pockmark answered 8/4, 2010 at 11:58 Comment(0)
D
132

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).

Deadhead answered 8/4, 2010 at 12:0 Comment(2)
What do you mean by "AMS environments that are designed for multiple equations (as opposed to multiline single equations)"?Socket
@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 \labels inside it will result in errorsDeadhead
A
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.

Agglutination answered 8/4, 2010 at 12:15 Comment(0)
F
12

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

Fricative answered 2/1, 2021 at 14:51 Comment(1)
That nonumber command helped me a lot, thanks!Carrizales
U
10

\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

Underlay answered 24/4, 2017 at 3:27 Comment(2)
Something important: this doesn't work in align, only align*.Choanocyte
Why are the tags to the left?Shoshanashoshanna
C
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}
Casaubon answered 17/1, 2014 at 15:40 Comment(0)
I
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

Intercession answered 28/12, 2016 at 14:19 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.