# Numbering of each equation within cases with left alignment (both on the page and within the equations)

I am trying to create a set of equations with curly braces (like cases), each with their own set of numbers derived from the subsection (such as can be done with equations using \numberwithin{equation}{subsection}). I get a good result where I want one equation number representing all cases of the equation (code below).

$$\mathbb(E)(X) = \int_{-\infty}^{\infty} xdF(x) = \left\{ \begin{array}{lll} \sum_{x \in \mathcal{X}} xf_{X}(x) & =\sum_{x \in \mathcal{X}}x \mathbb{P}(X=x) &\text{ if } X \text{ is discrete}\\ \\ \int_{-\infty}^{\infty} xf_{X}(x)dx & &\text{ if } X \text{ is continuous} \end{array} \right.$$


What can I do to to have each of the cases numbered individually?

I have tried align and numcases, but each of them has some problem - either the equation or the text aligns right, or the spacing goes awry.

Would appreciate some help for the specific example above, with

1. Equation aligned to left of page

2. All text within cells left aligned

3. Equation numbers on extreme right

4. An empty cell in the 2nd case and

5. A blank line in between the two cases.

• this should be helpful: Separate labels in cases. rather than a full blank line, an optional dimension value for the gap, e.g. [.6\baselineskip] would seem preferable. – barbara beeton Aug 16 '16 at 19:37
• Off-topic: It should be \mathbb{E}(X), not \mathbb(E)(X). – Mico Aug 16 '16 at 19:48
• Thanks Mico :). I actually use macros for those and made a typo while changin it to regular (non-macro) code for the forum. – Py_Dream Aug 17 '16 at 2:13

Another solution (and numbering) with the empheq package (which loads mathtools, which loads amsmath):

\documentclass{article}
\usepackage[a4paper,margin=2.5cm]{geometry} % set page parameters
\usepackage{amsfonts, % for \mathbb and \mathcal macros
empheq}%

\numberwithin{equation}{subsection}
\setcounter{section}{1}
\setcounter{subsection}{1}

\begin{document}

\begin{subequations}
\begin{empheq}[left={\mathbb{E}(X)=\displaystyle\int_{-\infty}^{\infty} x\,dF(x)=\empheqlbrace}]{alignat = 2}
& \sum_{x \in \mathcal{X}} xf_{X}(x) =\sum_{x \in \mathcal{X}} x\mathbb{P}(X=x)
&\qquad & \text{if $X$ is discrete}, \\
& \int_{-\infty}^{\infty} xf_{X}(x)\,dx
& &\text{if $X$ is continuous}. \end{empheq}
\end{subequations}

\begin{subequations}
\begin{empheq}[left={\mathbb{E}(X)=\displaystyle∫_{-∞}^{∞} x\,dF(x)=\empheqlbrace}]{flalign}
& ∑_{x ∈ \mathcal{X}} xf_{X}(x) =∑_{x ∈ \mathcal{X}} x\mathbb{P}(X=x)
& &\text{if $X$ is discrete},&\hspace{5em} & \\
& ∫_{-∞}^{∞} xf_{X}(x)\,dx
&& \text{if $X$ is continuous}. \end{empheq}
\end{subequations}

\end{document}


• Sorry. It's once more a problem with my editor. i'LL FIX IT. – Bernard Aug 16 '16 at 21:04
• Hi, many thanks for this. Can this be done without the global [fleqn] option? I don't want all equations left aligned. – Py_Dream Aug 17 '16 at 2:02
• Yes, absolutely. Actually, what formatting was not very clear, as you can see from some comments. So, to sum it up, you want equation numbers on the right, and centred alignments? – Bernard Aug 17 '16 at 8:01
• Hi Bernard, as mentioned in the original question, I am looking for this particular set of equations to be left aligned and the numbers to be right aligned. However, I do not want equations to be left-aligned globally, i.e., I do not want the global [fleqn] option. – Py_Dream Aug 18 '16 at 11:34
• @Py_Dream: You must use the flalign environment then. Please see my updated answer. – Bernard Aug 18 '16 at 11:56

You didn't specify the type of problem(s) you encounter with the numcases environment. At any rate, I don't seem to encounter any in the following example. (The fleqn option is set so that the entire equation is set flush-left instead of centered. If that's not needed, just drop that option.)

\documentclass[fleqn]{article}
\usepackage[a4paper,margin=2.5cm]{geometry} % set page parameters
\usepackage{amsfonts} % for \mathbb and \mathcal macros
\usepackage{amsmath}  % for \text and \numberwithin macros
\usepackage{cases}    % for numcases environment

%% And, just for this example:
\numberwithin{equation}{subsection}
\setcounter{section}{1}
\setcounter{subsection}{1}

\begin{document}
\begin{numcases}{\mathbb{E}(X) = \int_{-\infty}^{\infty} x\,dF(x)=}
\sum_{x \in \mathcal{X}} xf_{X}(x)  =
\sum_{x \in \mathcal{X}} x\mathbb{P}(X=x)
& \text{if $X$ is discrete} \\[1\baselineskip]
\int_{-\infty}^{\infty} xf_{X}(x)\,dx
& \text{if $X$ is continuous}
\end{numcases}
\end{document}

• Many thanks. I do not want to use the global [fleqn] option. So I was loading cases using \usepackage[fleqn]{cases} as was suggested somewhere. When I do this with your code (as on my earlier attempts), I get multiple errors for both the begin{numcases} line and the end{numcases} line. E.g. Undefined control sequence. ...}(X) = \int_{-\infty}^{\infty} x\,dF(x)=} Missing number, treated as zero. ...}(X) = \int_{-\infty}^{\infty} x\,dF(x)=} Illegal unit of measure (pt inserted). ...}(X) = \int_{-\infty}^{\infty} x\,dF(x)=} Is there any way to do this without the global [fleqn] option? – Py_Dream Aug 17 '16 at 2:05
• @Py_Dream - Under no circumstance should you attempt to pass the option fleqn to the cases package -- what you say "was suggested somewhere" is faulty. If you don't want to set the fleqn option at the \documentclass stage, you should set it as an option when loading the amsmath package: \usepackage[fleqn]{amsmath}. – Mico Aug 17 '16 at 5:33
• @Py_Dream - If you don't want all displayed equations to be left-aligned, certainly don't use the option fleqn option in the first place. If the non-centering should apply to just one displayed equation, you'll have to fine-tune its position "by hand", e.g., by using one or more \qquad instructions at the very end of the equation's right-hand most portion. – Mico Aug 17 '16 at 5:44
• Hi Mico, do you happen to have any further information (or links) on why fleqn should never be passed to the cases package and why the suggestion was faulty? It is not very helpful having cardinal truths stated without any reasons ascribed. – Py_Dream Aug 18 '16 at 11:37

Equation aligned to left of page: \documentclass[12pt,leqno]{book}

• I think you meant to specify fleqn, not leqno. – Mico Aug 16 '16 at 20:00
• @Mico: I had misunderstood, I guess. I'll change my code. Thanks! – Bernard Aug 16 '16 at 20:52