使用 alignat{2} 环境进行对齐

使用 alignat{2} 环境进行对齐

在下面的代码中,我进行了适当的对齐。所有等号都对齐了。有一个表达式写在两行上;我希望第一个加号对齐。我使用环境aligned[t]来获得这个。如何使用环境来获得这个alignat{2}

\documentclass[draft,a4paper,landscape]{amsart}
\usepackage{}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{newlfont}
\usepackage{mathtools,array}

\begin{document}

\noindent $a = x_{1} + iy_{1}$ and $z = x_{2} + iy_{2}$.
\begin{align*}
\big\vert 1 - \overline{a}z \big\vert^{2} &= \big\vert 1 - x_{1}x_{2} - y_{1}y_{2} + i(x_{1}y_{2} - x_{2}y_{1}) \big\vert^{2} \\
&= \begin{aligned}[t]1 &+ {x_{1}}^{2}{x_{2}}^{2} + {y_{1}}^{2}{y_{2}}^{2} - 2x_{1}x_{2} - 2y_{1}y_{2} + 2x_{1}x_{2}y_{1}y_{2} \\
&+ {x_{1}}^{2}{y_{2}}^{2} + {x_{2}}^{2}{y_{1}}^{2} - 2x_{1}x_{2}y_{1}y_{2}
\end{aligned} \\
&= \begin{aligned}[t]1 + {x_{1}}^{2}{x_{2}}^{2} + {y_{1}}^{2}{y_{2}}^{2} - 2x_{1}x_{2} - 2y_{1}y_{2} + {x_{1}}^{2}{y_{2}}^{2} + {x_{2}}^{2}{y_{1}}^{2}
\end{aligned} \\
&= \begin{aligned}[t]1 + ({x_{1}}^{2} + {y_{1}}^{2}) ({x_{2}}^{2} + {y_{2}}^{2}) - 2x_{1}x_{2} - 2y_{1}y_{2} ,
\end{aligned}
\intertext{and}
\vert z - a \vert^{2} &= \mathmakebox[0pt][l]{\vert x_{2} - x_{1} + i(y_{2} - y_{1}) \vert^{2}} \\
&= {x_{1}}^{2} + {x_{2}}^{2} + {y_{1}}^{2} + {y_{2}}^{2} - 2x_{1}x_{2} - 2y_{1}y_{2} .
\end{align*}

\end{document}

答案1

以下是使用该alignat环境的一种方法:

在此处输入图片描述

笔记:

  • \intertext用替换,\shortintertext因为我认为当文本非常小时这样看起来会更好,因为它会在文本前后增加较少的垂直空间。
  • 用于\mathrlap确保某些行的部分不会影响其他行的对齐。
  • 对齐尽可能多的二元运算符,只要我认为这些运算符有意义,且不重新组织方程式的项,或者不留下太多空白即可。根据需要进行调整。
  • 由于 _each&提供了一个rl对齐点,&&因此所有后续对齐点均使用了 double ,以便后面的文本&&左对齐。

参考:

代码:

\documentclass[draft,a4paper,landscape]{amsart}
\usepackage{}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{newlfont}
\usepackage{mathtools,array}


\begin{document}

\noindent $a = x_{1} + iy_{1}$ and $z = x_{2} + iy_{2}$.
\begin{alignat*}{7}
\big\vert 1 - \overline{a}z \big\vert^{2} 
&= \big\vert &&1 &&- x_{1}x_{2} - y_{1}y_{2} + \mathrlap{i(x_{1}y_{2} - x_{2}y_{1}) \big\vert^{2}} \\
&= && 1 &&+ {x_{1}}^{2}{x_{2}}^{2} + {y_{1}}^{2}{y_{2}}^{2} - 2x_{1}x_{2}  &&- 2y_{1}y_{2}  &&+ 2x_{1}x_{2}y_{1}y_{2} \\
& && &&+ {x_{1}}^{2}{y_{2}}^{2} + {x_{2}}^{2}{y_{1}}^{2}  && &&- 2x_{1}x_{2}y_{1}y_{2}  \\
&= && 1 &&+ {x_{1}}^{2}{x_{2}}^{2} + {y_{1}}^{2}{y_{2}}^{2} - 2x_{1}x_{2}  &&- 2y_{1}y_{2} &&+ {x_{1}}^{2}{y_{2}}^{2} + {x_{2}}^{2}{y_{1}}^{2} \\
&= && 1 &&+ ({x_{1}}^{2} + {y_{1}}^{2}) ({x_{2}}^{2} + {y_{2}}^{2}) &&- 2x_{1}x_{2} &&- 2y_{1}y_{2} ,
\shortintertext{and}% <--- Replaced \intertext
\vert z - a \vert^{2} &= \mathrlap{\vert x_{2} - x_{1} + i(y_{2} - y_{1}) \vert^{2}} \\
&= \mathrlap{{x_{1}}^{2} + {x_{2}}^{2} + {y_{1}}^{2} + {y_{2}}^{2} - 2x_{1}x_{2} - 2y_{1}y_{2}} .
\end{alignat*}

\end{document}

答案2

我认为使用 会太复杂alignat。实际上你只需要一个aligned环境。注意\!有一个精确的(第一个)对齐。

我认为没有必要对齐+第二行和第三行的符号。我更喜欢以不同的方式对齐,以便清楚地显示第三行是第二行的延续;我还缩小了这些行之间的垂直间距,因此,在我看来,这使得方程式更具可读性。

如果要使用的话alignat会更复杂 — 它会是 alignat{3}和一些\rlap命令:

\documentclass[draft,a4paper,landscape]{amsart}
\usepackage{}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{newlfont}
\usepackage{mathtools,array}

\begin{document}

\noindent $a = x_{1} + iy_{1}$ and $z = x_{2} + iy_{2}$.
\begin{align*}
\big\vert 1 - \overline{a}z \big\vert^{2} &= \big\vert 1 - x_{1}x_{2} - y_{1}y_{2} + i(x_{1}y_{2} - x_{2}y_{1}) \big\vert^{2} \\
&=\!\begin{aligned}[t]1 + x_{1}^{2}x_{2}^{2}+ y_{1}^{2}y_{2}^{2} &- 2x_{1}x_{2} - 2y_{1}y_{2} + 2x_{1}x_{2}y_{1}y_{2} \\[-0.5ex]
  & + x_{1}^{2}y_{2}^{2} + x_{2}^{2}y_{1}^{2} - 2x_{1}x_{2}y_{1}y_{2}
 \end{aligned}
 \\
&=1  + x_{1}^{2}x_{2}^{2} + y_{1}^{2}y_{2}^{2} - 2x_{1}x_{2} - 2y_{1}y_{2} + x_{1}^{2}y_{2}^{2} + x_{2}^{2}y_{1}^{2}
 \\
&= 1 + (x_{1}^{2} + y_{1}^{2}) (x_{2}^{2} + y_{2}^{2}) - 2x_{1}x_{2} - 2y_{1}y_{2} ,
\intertext{and}
\vert z - a \vert^{2} &= \mathmakebox[0pt][l]{\vert x_{2} - x_{1} + i(y_{2} - y_{1}) \vert^{2}} \\
&= x_{1}^{2} + x_{2}^{2} + y_{1}^{2} + y_{2}^{2} - 2x_{1}x_{2} - 2y_{1}y_{2} .
\end{align*}\vskip1cm

With an \texttt{alignat} environment,  it is much more complex: 
\begin{alignat*}{3}
\big\lvert 1 - \overline{a}z \big\rvert^{2} &= \mathrlap{\big\lvert 1   - x_{1}x_{2} - y_{1}y_{2}{}+ i(x_{1}y_{2} - x_{2}y_{1}) \big\rvert^{2}} \\
&= 1& &{}  + x_{1}^{2}x_{2}^{2}+ y_{1}^{2} y_{2}^{2}  &  &{} - 2x_{1}x_{2} - 2y_{1}y_{2} + 2x_{1}x_{2}y_{1}y_{2} \\[-0.5ex]
  & &  & &  &    + x_{1}^{2}y_{2}^{2} + x_{2}^{2}y_{1}^{2} - 2x_{1}x_{2}y_{1}y_{2}
 \\
&=1 &&{} + \mathrlap{x_{1}^{2}x_{2}^{2} + y_{1}^{2}y_{2}^{2} - 2x_{1}x_{2} - 2y_{1}y_{2} + x_{1}^{2}y_{2}^{2} + x_{2}^{2}y_{1}^{2}}
 \\
&=1& &{}+ \mathrlap{(x_{1}^{2} + y_{1}^{2}) (x_{2}^{2} + y_{2}^{2}) - 2x_{1}x_{2} - 2y_{1}y_{2} ,}
\intertext{and}
\vert z - a \vert^{2} &= \mathrlap{\vert x_{2} - x_{1} + i(y_{2} - y_{1}) \vert^{2}} \\
&=\mathrlap{ x_{1}^{2} + x_{2}^{2} + y_{1}^{2} + y_{2}^{2} - 2x_{1}x_{2} - 2y_{1}y_{2}.}
\end{alignat*}

\end{document} 

在此处输入图片描述

答案3

这是一个不使用环境的解决方案:

\documentclass[draft,a4paper,landscape]{amsart}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{newlfont}
\usepackage{mathtools}

\begin{document}

\noindent $a = x_{1} + iy_{1}$ and $z = x_{2} + iy_{2}$.
\begin{align*}
\big\vert 1 - \overline{a}z \big\vert^{2} &= \big\vert 1 - x_{1}x_{2} - y_{1}y_{2} + i(x_{1}y_{2} - x_{2}y_{1}) \big\vert^{2} \\
&= 1 + {x_{1}}^{2}{x_{2}}^{2} + {y_{1}}^{2}{y_{2}}^{2} - 2x_{1}x_{2} - 2y_{1}y_{2} + 2x_{1}x_{2}y_{1}y_{2} \\
&\phantom{{}=1} + {x_{1}}^{2}{y_{2}}^{2} + {x_{2}}^{2}{y_{1}}^{2} - 2x_{1}x_{2}y_{1}y_{2}\\
&= 1 + {x_{1}}^{2}{x_{2}}^{2} + {y_{1}}^{2}{y_{2}}^{2} - 2x_{1}x_{2} - 2y_{1}y_{2} + {x_{1}}^{2}{y_{2}}^{2} + {x_{2}}^{2}{y_{1}}^{2}\\
&= 1 + ({x_{1}}^{2} + {y_{1}}^{2}) ({x_{2}}^{2} + {y_{2}}^{2}) - 2x_{1}x_{2} - 2y_{1}y_{2} ,
\intertext{and}
\vert z - a \vert^{2} &= \vert x_{2} - x_{1} + i(y_{2} - y_{1}) \vert^{2} \\
&= {x_{1}}^{2} + {x_{2}}^{2} + {y_{1}}^{2} + {y_{2}}^{2} - 2x_{1}x_{2} - 2y_{1}y_{2} .
\end{align*}

\end{document}

在此处输入图片描述

你有很多括号,其实并不需要。这是我的方法:

\documentclass[draft,a4paper,landscape]{amsart}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{newlfont}
\usepackage{mathtools}

\begin{document}

\noindent $a = x_1 + iy_1$ and $z = x_2 + iy_2$.
\begin{align*}
\left| 1 - \overline{a}z \right|^2 &= \left| 1 - x_1x_2 - y_1y_2 + i\left(x_1y_2 - x_2y_1\right) \right|^2 \\
&= 1 + x_1^2x_2^2 + y_1^2y_2^2 - 2x_1x_2 - 2y_1y_2 + 2x_1x_2y_1y_2 \\
&\phantom{{}=1} + x_1^2y_2^2 + x_2^2y_1^2 - 2x_1x_2y_1y_2\\
&= 1 + x_1^2x_2^2 + y_1^2y_2^2 - 2x_1x_2 - 2y_1y_2 + x_1^2y_2^2 + x_2^2y_1^2\\
&= 1 + \left(x_1^2 + y_1^2\right) \left(x_2^2 + y_2^2\right) - 2x_1x_2 - 2y_1y_2 ,
\shortintertext{and}
\left| z - a \right|^2 &= \left| x_2 - x_1 + i\left(y_2 - y_1\right) \right|^2 \\
&= x_1^2 + x_2^2 + y_1^2 + y_2^2 - 2x_1x_2 - 2y_1y_2 .
\end{align*}

\end{document}

在此处输入图片描述

相关内容