使用调整宽度时,对齐方程式前会出现额外的一行

使用调整宽度时,对齐方程式前会出现额外的一行

我尝试在对齐环境中使用调整宽度环境,以使我的方程式不会被边距截断。当我这样做时,它会根据需要移动方程式,但它也会在我想要删除的方程式前面引入一个新的空白行。

\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{changepage}
To test this we have 
\begin{align*} 
asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf
\end{align*}
and then we also have
\begin{adjustwidth}{-3cm}{0cm}
\begin{align*} 
asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf
\end{align*}
\end{adjustwidth}

答案1

使用环境时添加的垂直空间adjustwidth可以通过在 \vspace{-\baselineskip}after\begin{adjustwidth}...和 before处添加来删除\end{adjustidth。为了简化符号,您可以像以下 MWE 中那样定义新环境:

\documentclass{article}

\usepackage{amsmath}
\usepackage{changepage}
\usepackage{lipsum}

\newenvironment{wide}[2]%
    {\begin{adjustwidth}{#1}{#2}
     \vspace{-\baselineskip}}
    {\end{adjustwidth}}

\begin{document}
\lipsum[1]
\begin{gather*}
asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf\\
asdfasdfasdfasdfasdfasdfasdfasdfasd
\end{gather*}
and then we also have
\begin{adjustwidth}{-33mm}{0cm}
    \vspace{-\baselineskip}
\begin{gather*}
asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf
\end{gather*}
    \vspace{-\baselineskip}
\end{adjustwidth}
\lipsum[2]
\begin{wide}{-33mm}{0cm}
\begin{gather*}
asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf
asdfasdfasdfasdfasdfasdfasdfasdfasd\end{gather*}
\end{wide}
\lipsum[3]
\end{document}

在此处输入图片描述

此解决方案的优点是您可以使用任何amsmath//mathtools数学empheq环境(如您在上面的 MWE 中所见)

答案2

是的,这会增加不必要的空间。这是一个没有这个问题的版本。

\documentclass{article}
\usepackage{amsmath}

\usepackage{lipsum}

\NewDocumentEnvironment{pushequationleft}{mo}
 {$$\hspace{-#1}\IfValueT{#2}{\begin{#2ed}}}
 {\IfValueT{#2}{\end{#2ed}}\hspace{1000pt minus 1fill}$$}

\begin{document}

\noindent\makebox[0pt][r]{\vrule width 3cm height 0.4pt}
\begin{pushequationleft}{3cm}
asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf
\end{pushequationleft}
\lipsum[1][1-4]
\begin{pushequationleft}{3cm}[align]
asdf &= asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf \\
asdf &= asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf
\end{pushequationleft}
\lipsum[2][1-4]
\begin{pushequationleft}{3cm}[gather]
asdf = asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf \\
asdf = asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf
\end{pushequationleft}
\lipsum[3][1-4]

\end{document}

对于多行显示,可选参数可以是aligngather

第一行表示等式被向左移动了恰好 3cm。

在此处输入图片描述

如果希望等式两边的数相同:

\documentclass{article}
\usepackage{amsmath}

\usepackage{lipsum}

\NewDocumentEnvironment{pushequationleft}{o}
 {$$\hspace{1000pt minus 1fill}\IfValueT{#1}{\begin{#1ed}}}
 {\IfValueT{#1}{\end{#1ed}}\hspace{1000pt minus 1fill}$$}

\begin{document}

\lipsum[4][1-4]
\begin{pushequationleft}
asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf
\end{pushequationleft}
\lipsum[1][1-4]
\begin{pushequationleft}[align]
asdf &= asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf \\
asdf &= asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf
\end{pushequationleft}
\lipsum[2][1-4]
\begin{pushequationleft}[gather]
asdf = asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf \\
asdf = asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf
\end{pushequationleft}
\lipsum[3][1-4]

\end{document}

在此处输入图片描述

无论如何,避免用于align*单一方程。

相关内容