54

How can I number several equations in a align environment using only one number?

For example

\begin{align}
w^T x_i + b \geqslant 1-\xi_i \text{ if } y_i=1, \nonumber \\
w^T x_i + b \leqslant -1+\xi_i \text{ if } y_i=-1,
\end{align}

The numbering will appear next to the second equation. But it would be better if it appears between the lines of the two equations.

In this case how to label this group of equations for later referring to?

Thanks and regards!

Tim
  • 1
  • 141
  • 372
  • 590

2 Answers2

82

First of all, you probably don't want the align environment if you have only one column of equations. In fact, your example is probably best with the cases environment. But to answer your question directly, used the aligned environment within equation - this way the outside environment gives the number:

\begin{equation}
  \begin{aligned}
  w^T x_i + b &\geq 1-\xi_i &\text{ if }& y_i=1,  \\
  w^T x_i + b &\leq -1+\xi_i & \text{ if } &y_i=-1,
  \end{aligned}
\end{equation}

The documentation of the amsmath package explains this and more.

Aniko
  • 18,516
  • 4
  • 48
  • 45
  • 3
    A little late here, but I want to add that this doesn't work the same as the `align` environment would: it fits the box to the width of the equations, and so the space between columns is often much smaller than it would otherwise be. – Ryan Reich May 05 '11 at 14:29
16

How about something like:

\documentclass{article}

\usepackage{amssymb,amsmath}

\begin{document}

\begin{equation}\label{A_Label}
  \begin{split}
    w^T x_i + b \geqslant 1-\xi_i \text{ if } y_i &= 1, \\
    w^T x_i + b \leqslant -1+\xi_i \text{ if } y_i &= -1
  \end{split}
\end{equation}

\end{document}

which produces:

enter image description here

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
  • How could you do this, but center both equations instead of anchoring them to each other? – Spencer Oct 19 '13 at 21:41
  • @SpencerBoucher TeX related questions have more or less become OT here on stackoverflow. I've also not spend time with TeX lately, so I recommend you to ask your question here: http://tex.stackexchange.com/ Good luck! – Bart Kiers Oct 20 '13 at 12:52
  • 1
    Thanks Bart. tex.SO is my go-to, but this popped up on a google search. For posterity and any future Googlers, just change the \split to \gather: `\begin{equation}\label{A_Label} \begin{gather} w^T x_i + b \geqslant 1-\xi_i \text{ if } y_i &= 1, \\ w^T x_i + b \leqslant -1+\xi_i \text{ if } y_i &= -1 \end{gather} \end{equation}` – Spencer Oct 21 '13 at 00:28
  • 2
    @SpencerBoucher The inner environment should be `gathered` instead of `gather`. – fefe Oct 22 '13 at 22:17
  • @JonasStein it was an image, but was removed. Added a new one using https://quicklatex.com – Bart Kiers Mar 14 '19 at 19:50