![在案例环境中对齐标签](https://linux22.com/image/336315/%E5%9C%A8%E6%A1%88%E4%BE%8B%E7%8E%AF%E5%A2%83%E4%B8%AD%E5%AF%B9%E9%BD%90%E6%A0%87%E7%AD%BE.png)
我有以下代码,其中有多个案例,所有案例都需要标记。我尝试使用subnumcases
,但我希望在标记方面有一定的自由度(第 k 个案例必须标记为 Ck 等),而使用该自定义包时我无法实现这一点。我还尝试使用两个对齐选项卡,使用alignat
,但这在案例环境中不起作用。
当我尝试手动标记时,标签没有右对齐,因此看起来很奇怪。 至少可以将手动方程标签右对齐吗? 或者有没有一种优雅的方式来呈现这些方程?
\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}
答案1
下面设置一个特定的numcases
环境来进行顺序编号C1、C2、Cķ,Cn使用\setupnumcases
。使用 恢复设置\restorenumcases
。
这个想法是更新\theequation
- 负责设置计数器或表示的宏equation
- 以按顺序设置特定的可能性列表。此序列由 决定\thesaveeqncntr
,它代替\theequation
。
\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}
\setupnumcases
为了对不同的内容进行不同的编号,必须进行更新numcases
。
答案2
像这样?
考虑到对问题的评论,代码使用了empheq
包以及multlined
包中的环境mathtools
,它被调用如下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}