将多线方程拟合到边距中

将多线方程拟合到边距中

我有这个等式。它很宽,我不得不把它分成两行。但是,左边的部分=很长,这给我带来了一些问题。

我在这里发布了一个 MWE。它产生了以下我几乎可以接受的结果(显然它太宽了 7.6 pt):

还行吧

问题是,当我在完整文档中有相同的等式时,它会在后面添加额外的空间=,现在肯定不行了:

这不行

我推测这是方程式编号较长的结果。有人能建议一种方法来让我的方程式适合页边距吗?我曾考虑过在符号后断开线=,但我希望=下线上的符号对齐,而这正是溢出到右侧的符号。我也曾考虑过在 之前断开=,并将符号对齐到左端,这将是最佳解决方案,但老实说,我不知道该怎么做。我怀疑我需要/或其他东西=的组合,但这让我很头疼!gathersplit

\documentclass[12pt, a4paper, oneside, fleqn]{report}

% Page geometry etc
%----------------------------
\usepackage{setspace}                % allow different line spacing
\renewcommand{\topfraction}{0.85}
\renewcommand{\textfraction}{0.1}
\usepackage[top=2.5cm, left=3.5cm, bottom=2.5cm, right=2.5cm, includehead]{geometry}
\geometry{headheight=28pt, headsep=18pt}

% Maths stuff
%------------
\usepackage{amsmath}

\begin{document}

\onehalfspacing
\mathindent=\parindent

The equation below is too wide for the page margins. The question is how best to format it so that it looks sensible but doesn't spill off the right hand margin?
\begin{alignat}{2}
{\textstyle \frac{1}{2}} \textrm{Cov}(\Delta_{i,p1}-\Delta_{i,p2},\Delta_{j,p1}-\Delta_{j,p2})
& = && {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p1},\Delta_{j,p1})
+ {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p2},\Delta_{j,p2})  - \notag \\
&   && {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p1},\Delta_{j,p2})
- {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p2},\Delta_{j,p1}) \\
& = && \textrm{Cov}(\Delta_{i,p1},\Delta_{j,p2})|_{p1=p2}
- \textrm{Cov}(\Delta_{i,p1},\Delta_{j,p2})|_{p1 \ne p2}
\end{alignat}


\end{document}

更新: 我刚刚开始进行收集,但是现在我的方程式数字远远偏离了正确方向,甚至在我的测试文档中也是如此:

\begin{gather}
{\textstyle \frac{1}{2}} \textrm{Cov}(\Delta_{i,p1}-\Delta_{i,p2},\Delta_{j,p1}-\Delta_{j,p2}) \notag \\
\begin{alignat}{2}
& = {} && {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p1},\Delta_{j,p1})
+ {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p2},\Delta_{j,p2})  - \notag \\
&   && {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p1},\Delta_{j,p2})
- {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p2},\Delta_{j,p1}) \\
& = {} && \textrm{Cov}(\Delta_{i,p1},\Delta_{j,p2})|_{p1=p2}
- \textrm{Cov}(\Delta_{i,p1},\Delta_{j,p2})|_{p1 \ne p2}
\end{alignat}
\end{gather}

收集

答案1

可以通过以下方式轻松编辑@JF Meier 的答案,以纠正“=”符号的对齐方式

\begin{align}
{\textstyle \frac{1}{2}} \textrm{Cov}(\Delta_{i,p1}-\Delta_{i,p2},&\Delta_{j,p1}-\Delta_{j,p2}) \notag \\
 = & {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p1},\Delta_{j,p1})
+ {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p2},\Delta_{j,p2})  - \notag \\
&    {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p1},\Delta_{j,p2})
- {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p2},\Delta_{j,p1}) \\
= & \textrm{Cov}(\Delta_{i,p1},\Delta_{j,p2})|_{p1=p2}
- \textrm{Cov}(\Delta_{i,p1},\Delta_{j,p2})|_{p1 \ne p2}
\end{align}

答案2

我会选择align,最简单的方法是屏蔽公共左侧的宽度,而不是固定任意对齐点。

\documentclass[12pt, a4paper, oneside, fleqn]{report}

% Page geometry etc
%----------------------------
\usepackage[top=2.5cm, left=3.5cm, bottom=2.5cm, right=2.5cm, includehead]{geometry}
\geometry{headheight=28pt, headsep=18pt}

% Maths stuff
%------------
\usepackage{mathtools}

\DeclareMathOperator{\Cov}{Cov}

\setlength{\mathindent}{\parindent}

\begin{document}
The equation below is too wide for the page margins. The question is how best 
to format it so that it looks sensible but doesn't spill off the right hand margin?
\begin{align}
{\textstyle \frac{1}{2}} \textrm{Cov}(\Delta_{i,p1}-\Delta_{i,p2},&\Delta_{j,p1}-\Delta_{j,p2}) \notag \\
 = & {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p1},\Delta_{j,p1})
+ {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p2},\Delta_{j,p2})  - \notag \\
&    {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p1},\Delta_{j,p2})
- {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p2},\Delta_{j,p1}) \\
= & \textrm{Cov}(\Delta_{i,p1},\Delta_{j,p2})|_{p1=p2}
- \textrm{Cov}(\Delta_{i,p1},\Delta_{j,p2})|_{p1 \ne p2}
\end{align}
Above is Chaplin's code, below it's mine.
\begin{align}
\mathmakebox[3\mathindent][l]{
  \tfrac{1}{2} \Cov(\Delta_{i,p1}-\Delta_{i,p2},\Delta_{j,p1}-\Delta_{j,p2})
}\notag \\
 ={}& \tfrac{1}{2}\Cov(\Delta_{i,p1},\Delta_{j,p1}) +
      \tfrac{1}{2}\Cov(\Delta_{i,p2},\Delta_{j,p2}) - {} \notag \\
    & \tfrac{1}{2}\Cov(\Delta_{i,p1},\Delta_{j,p2}) -
      \tfrac{1}{2}\Cov(\Delta_{i,p2},\Delta_{j,p1}) \\[\jot]
 ={}& \Cov(\Delta_{i,p1},\Delta_{j,p2})|_{p1=p2} -
      \Cov(\Delta_{i,p1},\Delta_{j,p2})|_{p1 \ne p2}
\end{align}


\end{document}

请注意包含数字的行之间的垂直间距,这有助于区分两个块。

您还可以轻松更改左侧的表观宽度,此处设置为数学缩进的三倍。如果您不想mathtools为此而加载,可以通过以下方式获得相同的外观

\hspace{3\mathindent}
\lefteqn{
  \hspace{-3\mathindent}
  \tfrac{1}{2} \Cov(\Delta_{i,p1}-\Delta_{i,p2},\Delta_{j,p1}-\Delta_{j,p2})
}\notag \\

在此处输入图片描述

答案3

我同意 JF Meier 的观点,但我是这样处理的。请注意,减号位于显示的数学行的开头,而不是结尾。

\documentclass{report}
\usepackage{amsmath,mathtools}
\DeclareMathOperator\Cov{Cov}
\begin{document}
\begin{align}
  \MoveEqLeft[3] 
  \tfrac{1}{2}
  \Cov(\Delta_{i,p1}-\Delta_{i,p2},\Delta_{j,p1}-\Delta_{j,p2}) 
  \notag \\
  = {} &
  \tfrac{1}{2}\Cov(\Delta_{i,p1},\Delta_{j,p1}) +
  \tfrac{1}{2}\Cov(\Delta_{i,p2},\Delta_{j,p2}) \notag
  \\
  & - \tfrac{1}{2}\Cov(\Delta_{i,p1},\Delta_{j,p2}) -
  \tfrac{1}{2}\Cov(\Delta_{i,p2},\Delta_{j,p1})
  \\
  = {} & \Cov(\Delta_{i,p1},\Delta_{j,p2})|_{p1=p2} -
  \Cov(\Delta_{i,p1},\Delta_{j,p2})|_{p1 \ne p2}
\end{align}
\end{document}

在此处输入图片描述


编辑,至于拉回来,我认为下图解释了这一点。在上图中,垂直线说明了对齐的位置,请注意与对齐的位置相比,后面的两条线是如何缩进的。

\MoveEqLeft与上图相同,但我们没有缩进第 2 行和第 3 行,而是消极的在第一行缩进(我们把它拉回来),给人一种第 2 行和第 3 行缩进的印象。(数学家很懒 ;-)

在此处输入图片描述

答案4

我建议这样的事情:

\begin{align}
{\textstyle \frac{1}{2}} \textrm{Cov}(\Delta_{i,p1}-\Delta_{i,p2},&\Delta_{j,p1}-\Delta_{j,p2}) \notag \\
& =  {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p1},\Delta_{j,p1})
+ {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p2},\Delta_{j,p2})  - \notag \\
&    {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p1},\Delta_{j,p2})
- {\textstyle \frac{1}{2}}\textrm{Cov}(\Delta_{i,p2},\Delta_{j,p1}) \\
& =  \textrm{Cov}(\Delta_{i,p1},\Delta_{j,p2})|_{p1=p2}
- \textrm{Cov}(\Delta_{i,p1},\Delta_{j,p2})|_{p1 \ne p2}
\end{align}

相关内容