大多数读者都会倾向于将这个问题标记为重复,因为我已经看到了很多关于这个问题的争论(但没有一个解决了这个问题)。我将首先发布我的 MWE,因为我有一些数学定义,您可以按照我的步骤在您的电脑上编译它。
\documentclass{article}
\usepackage[showframe]{geometry} %just to show the layout of the page
\usepackage{amsmath} % align, aligned, multline environments
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{verbatim}
\usepackage{xcolor}
%my custom commands for diff, deriv and pderiv
\makeatletter
\providecommand*{\diff}%
{\@ifnextchar^{\DIfF}{\DIfF^{}}}
\def\DIfF^#1{%
\mathop{\mathrm{\mathstrut d}}%
\nolimits^{#1}\gobblespace}
\def\gobblespace{%
\futurelet\diffarg\opspace}
\def\opspace{%
\let\DiffSpace\!%
\ifx\diffarg(%
\let\DiffSpace\relax
\else
\ifx\diffarg[%
\let\DiffSpace\relax
\else
\ifx\diffarg\{%
\let\DiffSpace\relax
\fi\fi\fi\DiffSpace}
\makeatother
\providecommand*{\deriv}[3][]{%
\frac{\diff^{#1}#2}{\diff #3^{#1}}
}
\providecommand*{\pderiv}[3][]{%
\frac{\partial^{#1}#2}{\partial #3^{#1}}
}
\begin{document}
This is the result with the \begin{verbatim} aligned \end{verbatim}
environment
\begin{equation}
\begin{aligned}
\bar{M}_{ab}^{(x)} &= \int_{\mathbb{R}^2}\diff{y}\diff{z}\hat\varepsilon_x e^{-{i}\left(k_yy+k_zz\right)}\left\{\psi_a^{\star}(\vec{r})\left[e^{-{i}(k_xx)}\hat\varepsilon_x\psi_b(\vec{r})\right]_{-\infty}^{\infty} +\right.\\
&\phantom{\mathrel{=}}- \left.\int_{\mathbb{R}}\diff{x}e^{-{i}(k_xx)}\hat\varepsilon_x\psi_b(\vec{r})\pderiv{\left(\psi^{\star}_a(\vec{r})\right)}x +\psi^{\star}_a(\vec{r})e^{-{i}(k_xx)}\hat\varepsilon_x\psi_b(\vec{r})\right\}\,
\end{aligned}
\end{equation}
\textcolor{blue}{This is the result with} \begin{verbatim} multline \end{verbatim}
environment
\begin{multline}
\bar{M}_{ab}^{(x)} = \int_{\mathbb{R}^2}\diff{y}\diff{z}\hat\varepsilon_x e^{-{i}\left(k_yy+k_zz\right)}\left\{\psi_a^{\star}(\vec{r})\left[e^{-{i}(k_xx)}\hat\varepsilon_x\psi_b(\vec{r})\right]_{-\infty}^{\infty} +\right.\\
- \left.\int_{\mathbb{R}}\diff{x}e^{-{i}(k_xx)}\hat\varepsilon_x\psi_b(\vec{r})\pderiv{\left(\psi^{\star}_a(\vec{r})\right)}x +\psi^{\star}_a(\vec{r})e^{-{i}(k_xx)}\hat\varepsilon_x\psi_b(\vec{r})\right\}\,
\end{multline}
\textcolor{blue}{the only one that does what I want, but does not work in align(ed) environment.}\\[10pt]
\par This is the result with \begin{verbatim} aligned + multlined + equation \end{verbatim}
environment
\begin{equation}
\begin{aligned}
\bar{M}_{ab}^{(x)} &\!\begin{multlined}[t]
= \int_{\mathbb{R}^2}\diff{y}\diff{z}\hat\varepsilon_x e^{-{i}\left(k_yy+k_zz\right)}\left\{\psi_a^{\star}(\vec{r})\left[e^{-{i}(k_xx)}\hat\varepsilon_x\psi_b(\vec{r})\right]_{-\infty}^{\infty} +\right.\\
- \left.\int_{\mathbb{R}}\diff{x}e^{-{i}(k_xx)}\hat\varepsilon_x\psi_b(\vec{r})\pderiv{\left(\psi^{\star}_a(\vec{r})\right)}x +\psi^{\star}_a(\vec{r})e^{-{i}(k_xx)}\hat\varepsilon_x\psi_b(\vec{r})\right\}\,
\end{multlined}\\
&=\text{other stuff I would like to add, but now the step above is not flushed to the right}
\end{aligned}
\end{equation}
\end{document}
我想要的是,通过在中断位于相同等式内时将它们向左刷新来突出显示数学关系链中的步骤,如果它们是链式方程的另一个步骤,则将它们对齐到同一点。让我们看一个例子。完全按照我想要的方式工作的环境是或multline
,multlined
实际上您可以看到以下代码
\begin{multline}
\bar{M}_{ab}^{(x)} = \int_{\mathbb{R}^2}\diff{y}\diff{z}\hat\varepsilon_x e^{-{i}\left(k_yy+k_zz\right)}\left\{\psi_a^{\star}(\vec{r})\left[e^{-{i}(k_xx)}\hat\varepsilon_x\psi_b(\vec{r})\right]_{-\infty}^{\infty} +\right.\\
- \left.\int_{\mathbb{R}}\diff{x}e^{-{i}(k_xx)}\hat\varepsilon_x\psi_b(\vec{r})\pderiv{\left(\psi^{\star}_a(\vec{r})\right)}x +\psi^{\star}_a(\vec{r})e^{-{i}(k_xx)}\hat\varepsilon_x\psi_b(\vec{r})\right\}\,
\end{multline}
产生以下输出
问题就在这里,我想通过添加另一条带有符号=
但与第一个对齐的数学线来继续相等链=
。所以我尝试了以下解决方案,可以通过编译我的 MWE 获得
那么如何以最简单的方式实现与上一个类似的结果,但中间步骤向右对齐?为什么最后一种解决方案不起作用?我真的不想实现奇怪的自定义命令,但为了获得更易读的代码,我更愿意使用这些环境来解决问题。感谢您的时间!
编辑:
@bernand 提出的原始解决方案很好,但不是我真正想要的,因为我正在寻找更自动化的东西,它不取决于你是否放置它,而是填充水平空间,这样如果我更改页面的边框,它将被正确拉伸,因为这个解决方案在具有不同布局的文档中不起作用
答案1
这是一个解决方案,将multlined
放在方便的位置。请注意,使用mathtools
,您不必加载amsmath
。我在差分符号后添加了一些间距。
\documentclass{article}
\usepackage[showframe]{geometry} %just to show the layout of the page
\usepackage{mathtools}% align, aligned, multline environments; extends amsmath
\usepackage{amssymb}
\usepackage{verbatim}
\usepackage{xcolor}
%my custom commands for diff, deriv and pderiv
\makeatletter
\providecommand*{\diff}%
{\@ifnextchar^{\DIfF}{\DIfF^{}}}
\def\DIfF^#1{%
\mathop{\mathrm{\mathstrut d}}%
\nolimits^{#1}\gobblespace}
\def\gobblespace{%
\futurelet\diffarg\opspace}
\def\opspace{%
\let\DiffSpace\!%
\ifx\diffarg(%
\let\DiffSpace\relax
\else
\ifx\diffarg[%
\let\DiffSpace\relax
\else
\ifx\diffarg\{%
\let\DiffSpace\relax
\fi\fi\fi\DiffSpace}
\makeatother
\providecommand*{\deriv}[3][]{%
\frac{\diff^{#1}#2}{\diff #3^{#1}}
}
\providecommand*{\pderiv}[3][]{%
\frac{\partial^{#1}#2}{\partial #3^{#1}}
}
\begin{document}
\begin{equation}
\begin{aligned}
\bar{M}_{ab}^{(x)} &
=\int_{\mathbb{R}^2}\diff{y}\diff{z}\,\hat\varepsilon_x e^{-{i}\left(k_yy+k_zz\right)} \begin{multlined}[t]\biggl\{\psi_a^{\star}(\vec{r})\Bigl[e^{-{i}(k_xx)}\hat\varepsilon_x\psi_b(\vec{r})\Bigr]_{-\infty}^{\infty} + \\
\mathllap{-}\int_{\mathbb{R}}\diff{x}\,e^{-{i}(k_xx)}\hat\varepsilon_x\psi_b(\vec{r})\pderiv{\left(\psi^{\star}_a(\vec{r})\right)}x +\psi^{\star}_a(\vec{r})e^{-{i}(k_xx)}\hat\varepsilon_x\psi_b(\vec{r})\biggr\}
\end{multlined}\\
&=\text{other stuff I would like to add, but now the step above is not flushed to the right}
\end{aligned}
\end{equation}
\end{document}