【问题标题】:Unwanted indentation in first line of multiline equation in LatexLatex 中多行方程的第一行中不需要的缩进
【发布时间】:2019-06-27 00:31:29
【问题描述】:

我在 Latex 中有一个很长的方程式,我需要将它分成几行。多行环境可以正常工作,只是第一行以令人讨厌的方式缩进。

我的方程左边很长,是九项的总和。

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{multline}a^2 X_1 X_2  + ab (X_1Y_2+X_2Y_1) + b^2 Y_1 Y_2 +\\
a^2 X_5 X_6  + ab (X_5Y_6+X_6Y_5) + b^2 Y_5 Y_6 +\\
a^2 X_9 X_{10} + ab (X_9Y_{10}+X_{10}Y_9) + b^2 Y_9 Y_{10} = 0
\end{multline}
\end{document}

最好将其分成三行,每行三个词,对齐以便词 1、4、7 相互重叠,2、5、8 和 3、6、9 也是如此。 RHS 只有 0,所以它可以留在最后一行(嗯,我的意思是……)。相反,我得到的是第一行缩进 - 向右移动 - 它通常在文本段落中完成。其他两行按我的意愿对齐。

我尝试了许多对齐命令,但都无济于事。

【问题讨论】:

  • 什么是多行环境?也许你的意思是来自 amsmath 的“多线”?或者,也许你使用非标准包?一般来说,需要一个包含所有包的最小工作示例,以便人们可以重现问题。您可以edit您的问题添加它。
  • 感谢您发现错字。我确实在使用多线,不管那是什么,但是当我将它更改为多线时,它并没有更好 - 我得到了多线典型的阶梯形布局,仍然不是我想要的“堆叠”对齐。我已经编辑了我的帖子以包含完整的代码。

标签: latex indentation multiline equation text-alignment


【解决方案1】:

引用自 amsmath 文档:

与多行一样,拆分环境适用于太长而无法放在一行中的单个方程,因此必须拆分为多行。然而,与多线不同的是,分割环境提供分割线之间的对齐,使用 & 来标记对齐点。

所以如果你想对齐线条,你可以试试split:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\[
\begin{split}
a^2 X_1 X_2  + ab (X_1Y_2+X_2Y_1) + b^2 Y_1 Y_2 +\\
a^2 X_5 X_6  + ab (X_5Y_6+X_6Y_5) + b^2 Y_5 Y_6 +\\
a^2 X_9 X_{10} + ab (X_9Y_{10}+X_{10}Y_9) + b^2 Y_9 Y_{10} = 0
\end{split}
\]

\[
\begin{split}
&a^2 X_1 X_2  + ab (X_1Y_2+X_2Y_1) + b^2 Y_1 Y_2 +\\
&a^2 X_5 X_6  + ab (X_5Y_6+X_6Y_5) + b^2 Y_5 Y_6 +\\
&a^2 X_9 X_{10} + ab (X_9Y_{10}+X_{10}Y_9) + b^2 Y_9 Y_{10} = 0
\end{split}
\]
\end{document}

要逐项对齐:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\[
\begin{aligned}
a^2 X_1 X_2  + &&ab (X_1Y_2+X_2Y_1) &&+b^2 Y_1 Y_2 &&+\\
a^2 X_5 X_6  + &&ab (X_5Y_6+X_6Y_5) &&+ b^2 Y_5 Y_6 &&+\\
a^2 X_9 X_{10} +&&ab (X_9Y_{10}+X_{10}Y_9) &&+ b^2 Y_9 Y_{10} &&= 0
\end{aligned}
\]
\end{document}

【讨论】:

  • 愿你长生不老,愿你的后代健康成长,愿你的骆驼永不误入歧途。每行开头带有&符号的版本就像一个魅力。 (没有和号,它在示例文件中也可以正常工作,但在我的全文中,无论出于何种原因,它向右刷新,因为最后的“= 0”而使底线向左伸出。再次感谢!
【解决方案2】:

很多方法可以对齐方程式中的线条,我不知道你想要什么。

这里有一些可能性:

  • 来自原版 LaTeX 的 eqnarray(但您可以看到间距很奇怪,不推荐使用它)。
  • 来自 amsmath 的 flaalign
  • 来自您使用的 amsmath 的多行。它的标准行为是左对齐第一行,右对齐最后一行并将其他行居中。您可以使用 \shoveright 或 \shoveleft 以不同的方式刷新一行并使用额外的空格(\qquad 或其他)控制其位置
  • 等式+从 amsmath 拆分,根据对齐选项卡的位置提供不同的对齐方式
  • 或者您可以让 Latex 决定在哪里使用 breqn 包和 dmath 环境进行换行。
\documentclass{article}
\usepackage{amsmath}
\usepackage{breqn}
\begin{document}

Eqnarray
\begin{eqnarray}
\notag a^2 X_1 X_2  &+& ab (X_1Y_2+X_2Y_1) + b^2 Y_1 Y_2 +\\
\notag&&a^2 X_5 X_6  + ab (X_5Y_6+X_6Y_5) + b^2 Y_5 Y_6 +\\
&&a^2 X_9 X_{10} + ab (X_9Y_{10}+X_{10}Y_9) + b^2 Y_9 Y_{10} = 0
\end{eqnarray}

flalign
\begin{flalign}
\notag a^2 X_1 X_2  + &ab (X_1Y_2+X_2Y_1) + b^2 Y_1 Y_2 +&\\
\notag&a^2 X_5 X_6  + ab (X_5Y_6+X_6Y_5) + b^2 Y_5 Y_6 +&\\
&a^2 X_9 X_{10} + ab (X_9Y_{10}+X_{10}Y_9) + b^2 Y_9 Y_{10} = 0
\end{flalign}


multline
\begin{multline}
a^2 X_1 X_2  + ab (X_1Y_2+X_2Y_1) + b^2 Y_1 Y_2 +\\
a^2 X_5 X_6  + ab (X_5Y_6+X_6Y_5) + b^2 Y_5 Y_6 +\\
a^2 X_9 X_{10} + ab (X_9Y_{10}+X_{10}Y_9) + b^2 Y_9 Y_{10} = 0
\end{multline}

multline+shovedright
\begin{multline}
a^2 X_1 X_2  + ab (X_1Y_2+X_2Y_1) + b^2 Y_1 Y_2 +\\
\shoveright{a^2 X_5 X_6  + ab (X_5Y_6+X_6Y_5) + b^2 Y_5 Y_6 +\qquad}\\
a^2 X_9 X_{10} + ab (X_9Y_{10}+X_{10}Y_9) + b^2 Y_9 Y_{10} = 0
\end{multline}

equation+split
\begin{equation}
  \begin{split}
a^2 X_1 X_2  &+ ab (X_1Y_2+X_2Y_1) + b^2 Y_1 Y_2 +\\
 &a^2 X_5 X_6  + ab (X_5Y_6+X_6Y_5) + b^2 Y_5 Y_6 +\\
 &a^2 X_9 X_{10} + ab (X_9Y_{10}+X_{10}Y_9) + b^2 Y_9 Y_{10} = 0\\   
  \end{split}
\end{equation}

equation+split flushed left
\begin{equation}
  \begin{split}
 & a^2 X_1 X_2  + ab (X_1Y_2+X_2Y_1) + b^2 Y_1 Y_2 +\\
 &a^2 X_5 X_6  + ab (X_5Y_6+X_6Y_5) + b^2 Y_5 Y_6 +\\
 &a^2 X_9 X_{10} + ab (X_9Y_{10}+X_{10}Y_9) + b^2 Y_9 Y_{10} = 0\\   
\end{split}
\end{equation}

equation+split flushed  right
\begin{equation}
  \begin{split}
 a^2 X_1 X_2  + ab (X_1Y_2+X_2Y_1) + b^2 Y_1 Y_2 +&\\
 a^2 X_5 X_6  + ab (X_5Y_6+X_6Y_5) + b^2 Y_5 Y_6 +&\\
 a^2 X_9 X_{10} + ab (X_9Y_{10}+X_{10}Y_9) + b^2 Y_9 Y_{10} = 0\\   
  \end{split}
\end{equation}

breqn+dmath
\begin{dmath}
a^2 X_1 X_2   + ab (X_1Y_2+X_2Y_1) + b^2 Y_1 Y_2 +
 a^2 X_5 X_6  + ab (X_5Y_6+X_6Y_5) + b^2 Y_5 Y_6 +
 a^2 X_9 X_{10} + ab (X_9Y_{10}+X_{10}Y_9) + b^2 Y_9 Y_{10} = 0
\end{dmath}
\end{document}

【讨论】:

  • 请考虑向eqnarray 添加一些警告,例如tug.org/pracjourn/2006-4/madsen 进行一些讨论
  • 你是对的(和往常一样)。我主要是出于历史原因将其包括在内,但它已被 ams 中的工具明显淘汰。谢谢。
【解决方案3】:

根据official docs(PDF 第 9 页),对于对齐的多行方程,请使用 split 环境:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation}
\begin{split}
  &a^2 X_1 X_2  + ab (X_1Y_2+X_2Y_1) + b^2 Y_1 Y_2 +\\
  &a^2 X_5 X_6  + ab (X_5Y_6+X_6Y_5) + b^2 Y_5 Y_6 +\\
  &a^2 X_9 X_{10} + ab (X_9Y_{10}+X_{10}Y_9) + b^2 Y_9 Y_{10} = 0
\end{split}
\end{equation}

\end{document}

输出:

【讨论】:

  • 这在运算符周围存在一些间距问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-31
  • 2019-05-15
相关资源
最近更新 更多