我正在使用多个案例环境,并使用对齐环境来对齐它们。一切看起来都应如此。
\documentclass{article}
\usepackage{amsmath}
\usepackage{cases}
\begin{document}
\begin{align*}
\delta(a, b) &=\begin{cases}
\begin{aligned}
\min(&1 + f(x, y) + d(x, y) \\
&1 + f(x, z) + d(x, z), \\
&f(a, b) + g(b, c), \\
&f(b, c) + g(a, b))
\end{aligned} & \text{condition 1,} \\
\begin{aligned}
\min(&1 + f(x, y) + d(x, y) \\
&1 + f(x, z) + d(x, z)), \\
\end{aligned} & \text{condition 2,} \\
0 & \text{condition 3}\\
+\infty & \text{otherwise,}
\end{cases} \\
\psi(a, b) &=
\begin{cases}
\min(f(a, b), f(b, c), f(c, d)) & \text{condition 1}, \\
\psi(a, b) & \text{condition 2}, \\
\delta(b, c) & \text{condition 3}
\end{cases}
\end{align*}
\end{document}
然而,一旦我将大小写改为数字大小写,一切都会出错,并且我会收到大量 TeX 错误。
\documentclass{article}
\usepackage{amsmath}
\usepackage{cases}
\begin{document}
\begin{align*}
\delta(a, b) &=\begin{numcases}
\begin{aligned}
\min(&1 + f(x, y) + d(x, y) \\
&1 + f(x, z) + d(x, z), \\
&f(a, b) + g(b, c), \\
&f(b, c) + g(a, b))
\end{aligned} & \text{condition 1,} \\
\begin{aligned}
\min(&1 + f(x, y) + d(x, y) \\
&1 + f(x, z) + d(x, z)), \\
\end{aligned} & \text{condition 2,} \\
0 & \text{condition 3}\\
+\infty & \text{otherwise,}
\end{numcases} \\
\psi(a, b) &=
\begin{numcases}
\min(f(a, b), f(b, c), f(c, d)) & \text{condition 1}, \\
\psi(a, b) & \text{condition 2}, \\
\delta(b, c) & \text{condition 3}
\end{numcases}
\end{align*}
\end{document}
这是带有 overleaf 原始错误日志的 pastebinhttps://pastebin.com/BMzMZKeQ
我猜这可能是因为 numcases 默认也提供对齐。我该如何更改代码来修复这个问题,并使用 numcases 和 cases 获得相同的结果?
答案1
您可以empheq
在 的帮助下使用两个环境eqparbox
。
\documentclass{article}
\usepackage{amsmath,empheq,eqparbox}
\newcommand{\eqmath}[3][c]{%
% #1 = alignment, default c, #2 = label, #2 = math material
\eqmakebox[#2][#1]{$\displaystyle#3$}%
}
\newcommand{\eqtext}[3][c]{%
% #1 = alignment, default c, #2 = label, #2 = text material
\eqmakebox[#2][#1]{#3}%
}
\begin{document}
\begin{empheq}[left={\eqmath[r]{A}{\delta(a,b)=}\empheqlbrace}]{alignat=2}
&\eqmath[l]{B}{\begin{aligned}
\min(&1 + f(x, y) + d(x, y) \\
&1 + f(x, z) + d(x, z), \\
&f(a, b) + g(b, c), \\
&f(b, c) + g(a, b))
\end{aligned}} &\qquad& \eqtext[l]{C}{condition 1,} \\
&\eqmath[l]{B}{\begin{aligned}
\min(&1 + f(x, y) + d(x, y) \\
&1 + f(x, z) + d(x, z)), \\
\end{aligned}} &\qquad& \eqtext[l]{C}{condition 2,} \\
&\eqmath[l]{B}{0} &\qquad& \eqtext[l]{C}{condition 3}\\
&\eqmath[l]{B}{+\infty} &\qquad& \eqtext[l]{C}{otherwise,}
\end{empheq}
\begin{empheq}[left={\eqmath[r]{A}{\psi(a,b)=}\empheqlbrace}]{alignat=2}
&\eqmath[l]{B}{\min(f(a, b), f(b, c), f(c, d))} &\qquad& \eqtext[l]{C}{condition 1,} \\
&\eqmath[l]{B}{\psi(a, b)} &\qquad& \eqtext[l]{C}{condition 2,} \\
&\eqmath[l]{B}{\delta(b, c)} &\qquad& \eqtext[l]{C}{condition 3}
\end{empheq}
\end{document}
标签A
、B
和C
是任意的。您需要不同的\eqmath
标签如果您再次使用和的技巧\eqtext
。
答案2
在我看来,您无法对齐两个numcases
环境。您的代码有两个问题:
numcases
需要一个参数,在你的情况下例如\delta(a,b)=
被添加到大小写区别的前面。numcases
似乎无法在任何方程环境中起作用。
我修复了你的代码,至少它能正常numcases
工作,但直到现在我还没有解决对齐问题的方法。乍一看它们似乎是对齐的,但实际上并非如此。
\documentclass{article}
\usepackage{amsmath}
\usepackage{cases}
\begin{document}
\begin{numcases}{\delta(a,b)=}
\begin{aligned}
\min(&1 + f(x, y) + d(x, y) \\
&1 + f(x, z) + d(x, z), \\
&f(a, b) + g(b, c), \\
&f(b, c) + g(a, b))
\end{aligned} & \text{condition 1,} \\
\begin{aligned}
\min(&1 + f(x, y) + d(x, y) \\
&1 + f(x, z) + d(x, z)), \\
\end{aligned} & \text{condition 2,} \\
0 & \text{condition 3}\\
+\infty & \text{otherwise,}
\end{numcases}
\begin{numcases}{\psi(a, b) =}
\min(f(a, b), f(b, c), f(c, d)) & \text{condition 1}, \\
\psi(a, b) & \text{condition 2}, \\
\delta(b, c) & \text{condition 3}
\end{numcases}
\end{document}