4

I have an equation written in the following way

\usepackage{amsmath}
.................

\[
f(x)= \begin{cases}
 e^x, & x\in [-1,1], \\
[x], &  x\notin [-1,1].
\end{cases}
\]

However, this leaves the equation with no number. Adding a \label{test} does not help. How do I fix that?

  • 3
    Instead of \[ and \], use an equation environment: \documentclass{article} \usepackage{amsmath} \begin{document} \begin{equation} f(x)= \begin{cases} e^x, & x\in [-1,1], \\ [x], & x\notin [-1,1]. \end{cases} \end{equation} \end{document} – leandriis Apr 1 at 13:45
  • 2
    Single equation number? Then see leandris' comment, equation number for each item in the cases, see the similar example in the empheq manual. – daleif Apr 1 at 13:48
  • 2
    To complement daleif's comment, you coud write with empheq : \documentclass{article} \usepackage{empheq} \begin{document} \begin{empheq}[left={f(x) = \empheqlbrace}]{align} e^x, & x\in [-1,1], \\[x], & x\notin [-1,1].\end{empheq}\end{document}. And if you want number.letter numbering of each line, you can wrap the empheq inside a subequations environment after loading the subequations package – BambOo Apr 1 at 14:22
  • Thank you guys - I'm happy to accept any/all of those as an answer if you would like to post them. – user1936752 Apr 1 at 17:02
  • 5
    Does this answer your question? How to add optional arguments to a package I'm writing? – oliversm Apr 1 at 23:14
6

You can do that with the package witharrows. In the following example, I have used the option subequations in order to have a sub-numerotation of the equations.

As the main goal of witharrows was, as its name says, to draw extra arrows, I have added an arrow in the example.

\documentclass{article}
\usepackage{amsmath}
\usepackage{witharrows}

\begin{document}
\begin{DispWithArrows}<f(x)=>[format = ll,subequations]
 e^x,\quad & x\in [-1,1], 
\Arrow[tikz=-]{two cases} \\
[x], &  x\notin [-1,1].
\end{DispWithArrows}
\end{document}

Result of the above code

| improve this answer | |

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