帮助 alignat 环境

帮助 alignat 环境
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat*}{3}
    &\text{Case 1: } s^*\leq a&\quad &\hphantom{\leq} 2\beta \leq& 2a\alpha-4\lambda-\tau &\Rightarrow s^* = \frac{2\beta+4\lambda+\tau}{2\alpha}\\
    &\text{Case 2: } a < s^* \leq b&\quad 2a\alpha-4\lambda+\tau &\leq 2\beta \leq& 2b\alpha-4\lambda+\tau &\Rightarrow s^*=\frac{2\beta+4\lambda-\tau}{2\alpha}\\
    &\text{Case 3: } b < s^* \leq c&\quad 2b\alpha-2\lambda+\tau &\leq 2\beta \leq& 2c\alpha-2\lambda+\tau &\Rightarrow s^* = \frac{2\beta+2\lambda-\tau}{2\alpha}\\
    &\text{Case 4: } c < s^* \leq d&\quad 2c\alpha+\tau &\leq 2\beta \leq& 2d\alpha+\tau &\Rightarrow s^* = \frac{2\beta-\tau}{2\alpha}\\
    &\text{Case 5: } d < s^* \leq e&\quad 2d\alpha+2\lambda+\tau &\leq 2\beta \leq& 2e\alpha+2\lambda+\tau & \Rightarrow s^* = \frac{2\beta-2\lambda-\tau}{2\alpha}\\
    &\text{Case 6: } e < s^*&\quad 2e\alpha+4\lambda+\tau &\leq 2\beta \hphantom{\leq}& &\Rightarrow s^* = \frac{2\beta-4\lambda-\tau}{2\alpha}
\end{alignat*}
\end{document}

上述代码生成 PDF 格式的结果为:

PDF 输出

除第 4 行外,其他都正确。为什么对齐2d\alpha+\tau正确?如何才能使其立即与对齐\leq

答案1

为了获得更好的对齐,您可以使用以下命令(忘记 s \hphantom):

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{alignat*}{9}
  & \text{Case 1: }&      & s^* &\leq a &                          &         &&        2\beta & \leq  {}&& 2a\alpha - 4\lambda &{}- \tau &&{} \Rightarrow {}& s^* &{}={}& \frac{2\beta + 4\lambda + \tau}{2\alpha}\\
  & \text{Case 2: }& a <{}& s^* &\leq b &\quad 2a\alpha - 4\lambda &{}+ \tau &&{} \leq 2\beta & \leq  {}&& 2b\alpha - 4\lambda &{}+ \tau &&{} \Rightarrow {}& s^* &{}={}& \frac{2\beta + 4\lambda - \tau}{2\alpha}\\
  & \text{Case 3: }& b <{}& s^* &\leq c &\quad 2b\alpha - 2\lambda &{}+ \tau &&{} \leq 2\beta & \leq  {}&& 2c\alpha - 2\lambda &{}+ \tau &&{} \Rightarrow {}& s^* &{}={}& \frac{2\beta + 2\lambda - \tau}{2\alpha}\\
  & \text{Case 4: }& c <{}& s^* &\leq d &\quad 2c\alpha            &{}+ \tau &&{} \leq 2\beta & \leq  {}&& 2d\alpha            &{}+ \tau &&{} \Rightarrow {}& s^* &{}={}& \frac{2\beta            - \tau}{2\alpha}\\
  & \text{Case 5: }& d <{}& s^* &\leq e &\quad 2d\alpha + 2\lambda &{}+ \tau &&{} \leq 2\beta & \leq  {}&& 2e\alpha + 2\lambda &{}+ \tau &&{} \Rightarrow {}& s^* &{}={}& \frac{2\beta - 2\lambda - \tau}{2\alpha}\\
  & \text{Case 6: }& e <{}& s^* &       &\quad 2e\alpha + 4\lambda &{}+ \tau &&{} \leq 2\beta &         &&                     &         &&   \Rightarrow {}& s^* &{}={}& \frac{2\beta - 4\lambda - \tau}{2\alpha}
\end{alignat*}

\end{document}

输出

答案2

您可以重新排列&以找到更好的对齐方式,但请记住,-符号被两个中等空格包围(TeXbook,第 167 页)。因此,如果我们写:

&\text{Case 4: } c < s^* \leq d&\quad 2c\alpha\phantom{\:-\:2\lambda}+\tau &\leq 2\beta \leq& 2d\alpha\phantom{\:-\:2\lambda}+\tau &\Rightarrow s^* = \frac{2\beta-\tau}{2\alpha}

我们将得到

在此处输入图片描述

相关内容