对齐环境而不是对齐单个操作员

对齐环境而不是对齐单个操作员

因此,我正在排版我给出的测验答案,而对齐环境(在我的方程式环境中)仅对我的一个运算符给出了不正确的对齐。这是我关注的一批代码:

\documentclass[12pt]{article}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
  \begin{aligned}
    x=-2 &\Rightarrow \frac{-2+1}{-2-4} &= \frac{-1}{-6} &= \frac{1}{6} &> 0 \\
    x=0 &\Rightarrow \frac{0+1}{0-4} &= \frac{1}{-4} &= -\frac{1}{4} &< 0 \\
    x=5 &\Rightarrow \frac{5+1}{5-4} &= \frac{6}{1} &= 6 &> 0
  \end{aligned}
\end{equation*}

\end{document}

代码输入的图像输出

当我运行此程序来创建 PDF 时,6/1 前面最后一行的等号出现在其上方两个等号的右侧。有没有什么办法可以解决这个问题,或者为什么会出现这种情况?

答案1

对齐环境在列之间交替右对齐/左对齐,因此您需要几个双&字符来将对齐更改为所需的形式。如果我理解您的愿望,它可能是这样的(也可能不是):

\documentclass[12pt]{article}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
  \begin{aligned}
    x=-2 &\Rightarrow \frac{-2+1}{-2-4} &&= \frac{-1}{-6} &&= \frac{1}{6} &> 0 \\
    x=0 &\Rightarrow \frac{0+1}{0-4} &&= \frac{1}{-4} &&= -\frac{1}{4} &< 0 \\
    x=5 &\Rightarrow \frac{5+1}{5-4} &&= \frac{6}{1} &&= 6 &> 0
  \end{aligned}
\end{equation*}

\end{document}

答案2

交替右/左/右/左/的对齐点aligned... 您还可以通过每行中第一个=符号的对齐注意到这种效果。还假设每个右/左对都是独立的,这就是为什么两个地方的段之间有更大的空间。

由于此表达式的单元格并非都包含减号,因此它们的宽度永远不会相同。

如果您希望所有关系都对齐,则应使用alignedat 而不是aligned,这样可以消除“对”之间的多余空格。(这需要一个附加条件,即 后的括号中的“列”数\begin{alignedat}

然后,您可以在“未对齐”关系符号前面加倍&,以将它们对齐。由于alignedat这不符合关系周围的通常间距,因此您应该{}在第一行受影响的符号之前插入(其他行将与第一行对齐)。

我在这个例子中有些过度使用,插入幻影来对齐带有“缺失”减号的元素。

\documentclass[12pt]{article}
\usepackage{amsmath}

\newcommand{\0}{\phantom{-}}
\begin{document}

\begin{equation*}
  \begin{alignedat}{5}
    x&=-2 &{}\Rightarrow \frac{-2+1}{-2-4} &&{}= \frac{-1}{-6} &&{}= \0\frac{1}{6} &&{}> 0 \\
    x&= \0 0 &\Rightarrow \0\frac{0+1}{0-4} &&= \frac{1}{-4} &&= -\frac{1}{4} &&< 0 \\
    x&= \0 5 &\Rightarrow \0\frac{5+1}{5-4} &&= \0\frac{6}{1} &&= \0 6 &&> 0
  \end{alignedat}
\end{equation*}

\end{document}

示例代码的输出

(我不确定为什么=最后一行的最后一个没有正确对齐;我必须调查一下。)

相关内容