我正在尝试生成这个等式:
使用以下内容:
\begin{equation}
d(T,b)=\left\{\begin{matrix}
0 & \mathrm{if branch has been covered,}\\
v(d_{min}(t\in T, b)) & \mathrm{if the predicate has been executed at least twice,}\\
1 & \mathrm{otherwise.}
\end{matrix}\right.
\end{equation}
但我得到了这个:
首先,我该如何修复对齐方式,使其与上面代码片段中的对齐方式完全相同?另外,我该如何修复右侧的文本?包括第二个值中的换行符?
答案1
cases
使用专用环境或其dcases*
变体(由 定义)来执行此操作要简单得多mathtools
:
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{equation}
d(T,b)=\begin{dcases*}
0 & if branch has been covered, \\
v(d_{\min}(t\in T, b)) & \parbox[t]{15em}{if the predicate has been executed at least twice,}\\
1 & otherwise. \\
\end{dcases*}
\end{equation}
\end{document}
答案2
为了不猜测宽度,您可以使用tabular
:
\documentclass{article}
\usepackage{amsmath}
\newcommand{\btext}[1]{%
\begingroup\renewcommand{\arraystretch}{1}%
\begin{tabular}[t]{@{}l@{}}#1\end{tabular}
\endgroup
}
\begin{document}
\begin{equation}
d(T,b)=
\begin{cases}
0 & \text{if branch has been covered,}\\[0.5ex]
v(d_{\min}(t\in T, b)) & \btext{if the predicate has been \\
executed at least twice,}\\[3ex]
1 & \text{otherwise.}
\end{cases}
\end{equation}
\end{document}
的(本地)重置\arraystretch
是必要的,因为cases
会改变它。仍然需要一些猜测,以便分离行。
答案3
这只是array
和的组合matrix
……但对于环境来说,cases
这是公正且正确的解决方案。
\documentclass[a4paper,12pt]{article}
\usepackage{mathtools,amssymb}
\begin{document}
\begin{equation*}
d(T,b)=\left\{\begin{array}{lll}
0 \\
v(d_{\min}(t\in T, b)) \\
1
\end{array}\right.
\begin{matrix*}[l]
\text{if branch has been covered,} & \\
\text{if the predicate has been executed at least twice,}& \\
\text{otherwise.}
\end{matrix*}
\end{equation*}
\end{document}
答案4
您可以使用这个包来做这件事cases
。
\documentclass{article}
\usepackage{cases}
\begin{document}
\begin{numcases}{d(T,b)=}
0 & if branch has been covered, \nonumber \\
v(d_{\mathrm{min}}(t\in T,b)) & \parbox[t]{11em}{if the predicate has been executed at least twice,} \nonumber \\
1 & otherwise \nonumber
\end{numcases}
\end{document}