1

I have the following code, where I have multiple cases and all need to be labelled. I tried using subnumcases, however I wanted some freedom in labelling (the $k^{th}$ case must be labelled C.k etc), which I could not achieve when using that custom package. I also tried to use two alignment tabs, using alignat, but that does not work inside cases environment.

When I tried to label manually, the labels are not right-aligned, and as such they appear odd. Is it possible to at least right align the manual equation labels? Or is there an elegant way to present these equations?

\documentclass[a4paper]{article}
\usepackage{geometry}
\geometry{left=1in,right=1in,top=1in,bottom=1in}
\usepackage{amsmath, amsfonts, amssymb, bbm, cases}

\begin{document}
 \begin{align*}
f(x) =
 \begin{cases}
   x_1, & \text{if } x\in(\sum_{i=1}^n b_i\log(a_i/b_i)-(\sum_{i=1}^n b_i) \log(a_1/b_1),\infty),\quad \text{(C\textsubscript{1})}\\
  x_2, & \text{if } x\in (\sum_{i=2}^n b_i\log(a_i/b_i) -(\sum_{i=2}^n b_i) \log(a_2/b_2), \\ & \sum_{i=1}^n b_i\log(a_i/b_i) -(\sum_{i=1}^n b_i)\log(a_1/b_1)),\quad \text{(C\textsubscript{2})} \\
   & \vdots \\
   x_k, & \text{if } x\in (\sum_{i=k}^n b_i\log(a_i/b_i) -(\sum_{i=k}^n b_i) \log(a_k/b_k), \\ &\sum_{i=k-1}^n b_i\log(a_i/b_i) -(\sum_{i=k-1}^n b_i)\log(a_{k-1}/b_{k-1})),\quad \text{(C\textsubscript{k})}\\
   & \vdots \\
   x_n, & \text{if } x\in (0, \sum_{i=n-1}^n b_i\log(a_i/b_i) -(\sum_{i=n-1}^n b_i) \log(a_n/b_n)),\quad \text{(C\textsubscript{n})}.
 \end{cases}
\end{align*}
\end{document}
2
  • 2
    See the empheq package, I think it is even an example in the manual. Btw: you have an error, there is no A4 class option it us called a4paper
    – daleif
    Jun 21, 2016 at 16:35
  • Off-topic: \geometry{left=1in,right=1in,top=1in,bottom=1in} may be written more succinctly as \geometry{margin=1in}.
    – Mico
    Jun 21, 2016 at 16:53

2 Answers 2

2

The following sets up a specific numcases environment to have the sequential numbering C1, C2, Ck, Cn using \setupnumcases. The setup is restored using \restorenumcases.

The idea is to update \theequation - the macro responsible for setting the equation counter or representation - to set a specific list of possibilities in sequence. This sequence is dictated by \thesaveeqncntr, which is used in place of \theequation.

enter image description here

\documentclass{article}
\usepackage[margin=1in]{geometry}% Just for this example
\usepackage{amsmath,cases}

\newcounter{saveeqncntr}
\renewcommand{\thesaveeqncntr}{\ifcase\value{equation} % 0
  \or $C_1$ % 1
  \or $C_2$ % 2
  \or $C_k$ % 3
  \or $C_n$ % 4
  \else ? % 5+
  \fi}%
\newcommand{\setupnumcases}{%
  \setcounter{saveeqncntr}{\value{equation}}% Store equation counter
  \setcounter{equation}{0}%
  \let\theequation\thesaveeqncntr}
\newcommand{\restorenumcases}{%
  \setcounter{equation}{\value{saveeqncntr}}% Restore equation counter
  \renewcommand{\theequation}{\arabic{equation}}%
  \ignorespaces}

\begin{document}

An equation before
\begin{equation}
  f(x) = ax^2 + bx + c.
\end{equation}

Some text before.%
\setupnumcases
\begin{numcases}{f(x) =}
  x_1, & if $x \in (\sum_{i=1}^n b_i\log(a_i/b_i) - (\sum_{i=1}^n b_i) \log(a_1/b_1),\infty)$, \\
  x_2, & if $x \in (\sum_{i=2}^n b_i\log(a_i/b_i) - (\sum_{i=2}^n b_i) \log(a_2/b_2)$, \nonumber \\
  & $\sum_{i=1}^n b_i\log(a_i/b_i) - (\sum_{i=1}^n b_i)\log(a_1/b_1))$, \\
  & $\vdots$ \nonumber \\
  x_k, & if $x \in (\sum_{i=k}^n b_i\log(a_i/b_i) - (\sum_{i=k}^n b_i) \log(a_k/b_k)$, \nonumber \\
  & $\sum_{i=k-1}^n b_i\log(a_i/b_i) - (\sum_{i=k-1}^n b_i)\log(a_{k-1}/b_{k-1}))$, \\
  & $\vdots$ \nonumber \\
  x_n, & if $x \in (0, \sum_{i=n-1}^n b_i\log(a_i/b_i) - (\sum_{i=n-1}^n b_i) \log(a_n/b_n))$.
\end{numcases}
\restorenumcases
Some text after. And an equation after
\begin{equation}
  f(x) = ax^2 + bx + c.
\end{equation}

\end{document}

One would have to update \setupnumcases in order to have a different numbering to a differing numcases.

2

Like this?

enter image description here

Considering comments to question, the code employ empheq package and also environment multlined from package mathtools, which is called by empheq:

\documentclass{article}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{empheq}

\begin{document}
 \begin{empheq}[left={f(x)=}\empheqlbrace]{align}
x_1,    & \text{ if } x\in
        \Biggl(\sum_{i=1}^n b_i\log(a_i/b_i)-
            \left(\sum_{i=1}^n b_i\right) \log(a_1/b_1),\infty
        \Biggr),                 \tag{C\textsubscript{1}}        \\
x_2,    & \begin{multlined}[t][0.6\textwidth]
            \text{ if } x\in 
        \Biggl(\sum_{i=2}^n b_i\log(a_i/b_i) - \sum_{i=2}^n b_i \log(a_2/b_2), \\
              \sum_{i=1}^n b_i\log(a_i/b_i) -
            \left(\sum_{i=1}^n b_i\right) \log(a_1/b_1)
        \Biggr),
        \end{multlined}
                                \tag{C\textsubscript{2}}        \\
        & \vdots                \notag                          \\
x_k,    & \begin{multlined}[t][0.6\textwidth]
            \text{ if } x\in
        \Biggl(\sum_{i=k}^n b_i\log(a_i/b_i)-\sum_{i=k}^n b_i \log(a_k/b_k), \\
            \sum_{i=k-1}^n b_i\log(a_i/b_i) -
            \left(\sum_{i=k-1}^n b_i\right) \log(a_{k-1}/b_{k-1})
        \Biggr),
        \end{multlined}
                                \tag{C\textsubscript{k}}        \\
        & \vdots                \notag                          \\
x_n,    & \text{ if }
        x\in 
        \Biggl(0, \sum_{i=n-1}^n b_i\log(a_i/b_i) -
            \left(\sum_{i=n-1}^n b_i\right) \log(a_n/b_n)
        \Biggr),
                                \tag{C\textsubscript{n}}
\end{empheq}
\end{document}
2
  • Mathtools does not provide aligned/align (you're using eq numbers), it comes from amsmath. However, if I'm not mistaken, for align I think a modified version of aligned is used, with custom eqn no placement
    – daleif
    Jun 21, 2016 at 18:09
  • 1
    huh, now I see mistake, I didn't use aligned, which is from amsmath but multlined, which is from mathtools. Thank you for pointed k me this.
    – Zarko
    Jun 21, 2016 at 18:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .