我想将以下代码第三行和第四行中的第一个“+”对齐。在第三行中,我有“= 3 + [a mess]”,在第四行中,我有“+ [another mess]”——第四行中没有“3”。我使用 \hphantom 命令来计算第三行中“= 3”的水平空间,但有一个小空间,即需要插入的二进制运算符(在本例中为加号)两侧的空间。(我在 amsart 中使用 10pt 字体。)以下是代码:
\begin{align*}
&\vert xy + xz + yz \vert^{2} \\
&\qquad = [\cos(a + b) + \cos(a + c) + \cos(b + c)]^{2}
+ [\sin(a + b) + \sin(a + c) + \sin(b + c)]^{2} \\
&\qquad = 3 + [2\cos(a + b)\cos(a + c)
+ 2\cos(a + b)\cos(b + c)
+ 2\cos(a + c)\cos(b + c)] \\
&\qquad \hphantom{= 3} + [2\sin(a + b)\sin(a + c)
+ 2\sin(a + b)\sin(b + c)
+ 2\sin(a + c)\sin(b + c)] .
\end{align*}
我尝试使用\phantom
命令与\mathbin{+}
命令,但这会将加号的水平空间添加到第四行。我尝试在给定的对齐环境中放置另一个对齐环境。
答案1
aligned[t]
在 内使用环境就足够了 align
。[t
选项是让对齐的环境按其顶行对齐;并且您不需要手动插入所有这些\qquad
s 来相对于以下内容移动第一行:mathtools
包(加载 amsmath)有一个\MoveEqLeft
命令:它接受一个可选参数,即您想要移动的 em 数(默认为 2)。它替换&
第一行的 。
但也许你会发现使用multlined
替代方法看起来也不错。我给出了两种解决方案的示例:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{amssymb,mathtools}
\usepackage{amsfonts}
\begin{document}
\begin{align*}
\MoveEqLeft[3]\vert xy + xz + yz \vert^{2} \\
& = [\cos(a + b) + \cos(a + c) + \cos(b + c)]^{2}
+ [\sin(a + b) + \sin(a + c) + \sin(b + c)]^{2} \\
& = \begin{aligned}[t]3 & + [2\cos(a + b)\cos(a + c)
+ 2\cos(a + b)\cos(b + c)
+ 2\cos(a + c)\cos(b + c)] \\
& + [2\sin(a + b)\sin(a + c)
+ 2\sin(a + b)\sin(b + c)
+ 2\sin(a + c)\sin(b + c)] .
\end{aligned}
\end{align*}
\begin{align*}
\MoveEqLeft[3]\vert xy + xz + yz \vert^{2} \\
& = [\cos(a + b) + \cos(a + c) + \cos(b + c)]^{2}
+ [\sin(a + b) + \sin(a + c) + \sin(b + c)]^{2} \\
& = \begin{multlined}[t]3 + [2\cos(a + b)\cos(a + c)
+ 2\cos(a + b)\cos(b + c)
+ 2\cos(a + c)\cos(b + c)] \\
+ [2\sin(a + b)\sin(a + c)
+ 2\sin(a + b)\sin(b + c)
+ 2\sin(a + c)\sin(b + c)] .
\end{multlined}
\end{align*}
\end{document}
答案2
我通常不缩进,而是将第一个术语缩进,并将其对齐到=
\documentclass[a4paper]{memoir}
\usepackage{amsmath,amssymb,mathtools}
\DeclarePairedDelimiter\abs\lvert\rvert
\begin{document}
\begin{align*}
\MoveEqLeft[3] \abs{xy + xz + yz}^{2}
\\
= {} & [\cos(a + b) + \cos(a + c) + \cos(b + c)]^{2}
\\
&+ [\sin(a + b) + \sin(a + c) + \sin(b + c)]^{2}
\\
={} & 3
\! % special feature
\begin{aligned}[t]
&+
\!% special feature
\begin{aligned}[t]
[&2\cos(a + b)\cos(a + c) + 2\cos(a + b)\cos(b +
c) \\
&+ 2\cos(a + c)\cos(b + c)]
\end{aligned}
\\
& +
\!
\begin{aligned}[t]
[&2\sin(a + b)\sin(a + c) + 2\sin(a + b)\sin(b +
c) \\
&+ 2\sin(a + c)\sin(b + c)] .
\end{aligned}
\end{aligned}
\end{align*}
\end{document}
答案3
% arara: pdflatex
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{align*}
\vert xy + xz + yz \vert^{2} &= [\cos(a + b) + \cos(a + c) + \cos(b + c)]^{2}\\
&\quad+ [\sin(a + b) + \sin(a + c) + \sin(b + c)]^{2} \\
&= 3 + [2\cos(a + b)\cos(a + c)\\
&\phantom{{}= 3} \quad + 2\cos(a + b)\cos(b + c)
+ 2\cos(a + c)\cos(b + c)] \\
&\phantom{{}= 3} + [2\sin(a + b)\sin(a + c)\\
&\phantom{{}= 3} \quad + 2\sin(a + b)\sin(b + c)
+ 2\sin(a + c)\sin(b + c)]
\end{align*}
\end{document}