为什么这个显示不正确:
\begin{equation}
steps(x^{(i)}) =
\begin{cases}
1 & \mbox{ if } x^{(i)}.g = leaf \\
1 + \sum_{g \in children(x) } steps(proof\_state(g)) & \mbox{otherwise}
\end{cases}
\end{equation}
我希望它是一个有案例的方程。它说
misplaced alignment tab character &
但根据其他例子,我觉得它看起来不错。
答案1
这个问题已经解决过一次
\usepackage{amsmath}
已添加至顶部。
答案2
我提出 3 种替代方案:
第一个选项:
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{equation}
\textup{steps}(x^{(i)}) =
\begin{cases}
1 & \textup{if } x^{(i)}.g = \textup{leaf}\\
&\\
1 + \displaystyle\sum_{g \in \textup{children(x)}} \textup{steps}(\textup{proof}\_\textup{state}(g)) & \textup{otherwise}
\end{cases}
\end{equation}
\end{document}
第二种选择:
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{equation}
\textup{steps}(x^{(i)}) =
\begin{cases}
1 & \textup{if } x^{(i)}.g = \textup{leaf}\\
1 + \displaystyle\sum_{g \in \textup{children(x)}} \textup{steps}(\textup{proof}\_\textup{state}(g)) & \textup{otherwise}
\end{cases}
\end{equation}
\end{document}
[![enter image description here][2]][2]
第三种选择:
\documentclass{article}
\usepackage{mathtools}
\usepackage{geometry}
\usepackage{lipsum}
\begin{document}
\lipsum[2-3]
\begin{equation}
\textup{steps}(x^{(i)}) =
\begin{cases}
1 & \textup{if } x^{(i)}.g = \textup{leaf}\\
&\\
1 + \displaystyle\sum_{g \in \textup{children(x)}} \textup{steps}(\textup{proof}\_\textup{state}(g)) & \textup{otherwise}
\end{cases}
\end{equation}
\lipsum[1]
\end{document}
答案3
我提出了两种基于empheq
包的变体,它们加载mathtools
,因此amsmath
。在第二种变体中,两个方程都已编号:
\documentclass{article}
\usepackage{empheq}
\begin{document}
\begin{empheq}[left={\text{steps}\bigl(x^{(i)}\bigr) =} \empheqlbrace]{equation}
\begin{alignedat}{2}
& 1 && \text{if } x^{(i)}.g = \text{leaf}\\
& 1 + \smashoperator{\sum_{g \in \text{children(x)}}} \text{steps}(\text{proof}\_\text{state}(g)) &\quad & \textup{otherwise}
\end{alignedat}
\end{empheq}
\bigskip
\begin{empheq}[left={\text{steps}\bigl(x^{(i)}\bigr) =} \empheqlbrace]{alignat=2}
& 1 && \text{if } x^{(i)}.g = \text{leaf}\\
& 1 + \smashoperator{\sum_{g \in \text{children(x)}}} \text{steps}(\text{proof}\_\text{state}(g)) &\quad & \textup{otherwise}
\end{empheq}
\end{document}