39

As much as I have tried, it doesn't seem possible to use separate labels when using a casesconstruction (from the amsmath package).

Ideally, I would like to be able to write something like

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
f(x)=\begin{cases}
  1&x\geq0\label{positive}\\
  0&x<0\label{negative}
\end{cases}
\end{equation}
\end{document}

and later refer to both cases at different places. What would be the best way to achieve this result?

42

You can use numcases from the cases package if you want each case labelled as a separate equation. There is also the subnumcases environment which gives you an alternative labelling:

enter image description here

\documentclass[preview]{standalone}
\usepackage{amsmath}
\usepackage{cases}
\begin{document}
\begin{numcases}{f(x)=}
   1 & $x\geq0$ \label{positive}
   \\
   0 & $x<0$ \label{negative}
\end{numcases}

See the second case \ref{negative} or the first \ref{positive}

\begin{subnumcases}{f(x)=}
   1 & $x\geq0$ \label{positive-subnum}
   \\
   0 & $x<0$ \label{negative-subnum}
\end{subnumcases}

See the second case \ref{negative-subnum} or the first \ref{positive-subnum}
\end{document}
  • 1
    Exactly what I needed! Worth mentioning is the subnum package option that turns every numcases environment into a subnumcases one. – FelixCQ Oct 19 '11 at 6:23
  • I've taken the liberty of adding the option preview to the \documentclass instruction. The default behavior of the standalone document class has changed since 2011, and your MWE won't compile correctly any longer without the preview option. – Mico Aug 3 '14 at 12:45
  • Hi, is it possible to use this method for a 'dcase' envirinment? – Fahim B Nov 9 '18 at 21:15
  • @FahimB: Good question. I don't know but would recommend you post a new question and link to this one as it is very much related. – Peter Grill Nov 9 '18 at 22:29
16

Using only the amsmath package and no additional packages, it is possible with some box manipulation:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\newsavebox{\mycases}% Store case "title" and brace
\begin{align}
  \sbox{\mycases}{$\displaystyle f(x)=\left\{\begin{array}{@{}c@{}}\vphantom{1\ x\geq0}\\\vphantom{0\ x<0}\end{array}\right.\kern-\nulldelimiterspace$}
  \raisebox{-.5\ht\mycases}[0pt][0pt]{\usebox{\mycases}}1 \quad x\geq0\label{positive} \\
     0 \quad x<0\label{negative}
\end{align}
\end{document}
  • 5
    Your method has the virtue of producing \labels that are handled correctly by \cref (of the cleveref package) cross-referencing commands, whereas the solution produced by the cases package -- see @PeterGrill's parallel answer -- does not. – Mico Aug 3 '14 at 12:55
  • 1
    Also, it's compatible with the refcheck package, as opposed the subnumcases solution. – Rastapopoulos Mar 15 at 17:26
13

You can combine the preceding solution with the subequations environment if you refer to the equations as a group. If you want to refer to the group, you have to introduce a \label just before entering the align environment. Here it is in action:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier}
\usepackage{heuristica}

\usepackage[overload]{empheq}
\usepackage{cleveref} 

 \begin{document}

\begin{subequations}
\label{Phi:def}
  \begin{align}[left ={Φ(A_n) = \empheqlbrace}]
    & \max \left [ L_n-A_n, 0 \right]\\
    & \max \left [ L_n-A_n, K \right]\label{eq:PayoffStopLosses}\\
    & \max \left [ L_n-A_n, K_1 \right] -\max \left [ A_n-L_n, K_2 \right]
   \end{align}
  \end{subequations}

As we can see in \cref{Phi:def}, and more specifically in \cref{eq:PayoffStopLosses},…

    \end{document} 

enter image description here

  • 1
    useful concept. please show what references (\eqref) would look like, for the group as a whole, and for one or more of the subequations. – barbara beeton May 28 '14 at 18:55
11

You can do this by the empheq package from the mh bundle.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{empheq}   % loads »mathtools«, which in turn loads »amsmath«

\begin{document}
  \begin{empheq}[left={f(x)=\empheqlbrace}]{align}
    1 &\quad x\geq0\label{positive}\\
    0 &\quad x<0\label{negative}
  \end{empheq}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.