在对齐的方程式之间添加多个段落

在对齐的方程式之间添加多个段落

有些人询问如何添加多个段落(当\intertext不再\shortintertext起作用时),Peter Grill 提出了一个解决方案这里

他写了:

我的第一个想法是将结果拆分开align,然后将这些行逐行分配到您想要的任何位置。唉,这align 会产生一个相当复杂的列表,不值得花精力去解开它(如果可能的话)。

因此我创建了自己的对齐环境,据我所知,它能align*完成您想要的功能,但会生成一个非常简单的列表。然后我的宏\ALineAgain会将该列表拆分开,并按照您的要求逐行删除。

因为实际给出对齐的位置不会打印行,所以使用 是没有意义的AlignAgain*;它从不打印方程编号。相反,该\ALineAgain宏采用星号来抑制方程编号的添加。

此代码的问题是,一旦您尝试引用方程编号,它们似乎就会变得混乱。下面,我只在 Peter 的代码中添加了几行代码(值得注意的是:\numberwithin{equation}{section},两个部分命令,然后在最后添加一行,尝试引用这两个方程)。

它不是打印 (1.1) 和 (1.2),而是打印 (1.1) 和 (1.1)。代码的方程部分似乎有问题。有人能发现问题吗?

\documentclass{article}
% \usepackage{showframe}
\usepackage{amsmath}

\numberwithin{equation}{section}

% It's like {align}, but simple!
\newenvironment{SimpleAlign}
{%
 \let\\=\cr
 \tabskip 0pt plus 1fil\relax
 \halign\bgroup
  &\hfil$\displaystyle ##$\tabskip 0pt\relax
  &$\displaystyle {}##$\hfil\tabskip 0pt plus 1fil\relax\cr
}
{%
 \crcr\egroup
}

% Saves its contents typeset like SimpleAlign.  You can give it a name.
\newenvironment{AlignAgain}[1][AlignBox]
{%
 \expandafter\let\expandafter\AlignAgainBox\csname #1\endcsname
 \setbox\AlignAgainBox=\vbox\bgroup\SimpleAlign
}
{%
 \endSimpleAlign\egroup
 \ReBox\AlignAgainBox
}
\newbox\AlignBox

% Prints the lines from {AlignAgain} one-by-one, with or without equation numbers as starred.  If you named the {AlignAgain}, use it here.
\makeatletter
\newcommand\ALineAgain{%
 \@ifstar
  {\AlignAgainStartrue\@ALineAgain}
  {\AlignAgainStarfalse\@ALineAgain}%
}
\newcommand\@ALineAgain[1][AlignBox]{%
 \expandafter\let\expandafter\AlignAgainBox\csname #1\endcsname
 \begin{equation*}
  \PutFirstBox\ifAlignAgainStar\AlignAgainBox
 \end{equation*}
}
\makeatother
\newif\ifAlignAgainStar

% Reboxes a box in the format: {[1][2]...[n]} -> {[1]{[2]{...}[n]}}
% {...} = \hbox
\newcommand{\ReBox}[1]
{%
 % To enter internal vertical mode, where \lastbox is valid
 \setbox0=\vbox{%
  \unvbox#1\relax
  \global\setbox#1=\hbox{\hbox{}}
  \loop
   \unskip
   %\box0 is the box currently at the end of #1
   \setbox0=\lastbox
  \ifvoid0\relax
  \else
   \global\setbox#1=\hbox{\box0\box#1}%
  \repeat
 }%
}

% Puts the first box in a nested-box list into the display, saving the rest back in #1
% Optionally places an equation number
\newcommand{\PutFirstBox}[2]{%
 \hbox to \displaywidth{%
  \unhbox#2\relax
  \global\setbox#2=\lastbox
  \setbox0=\lastbox
  \unhbox0%
  #1\else\refstepcounter{equation}\llap{(\theequation)}\fi
 }%
}

\begin{document}

\section{First section}
\subsection{A subsection}
Hello
\begin{AlignAgain}
 a &= b & c &= d \label{firsteqn} \\
 f(x) &= g(x) & h(x) &= e^{-1/x^2} \label{myeqn} \\
\end{AlignAgain}

This is a paragraph with a lot of redundant words whose only purpose is to extend it onto a new line or two so it's dramatic when I display this equation:
\ALineAgain
and then follow it with a bunch more text.

And also a new paragraph, just for good measure.  I wonder if the two equations will line up?  I sure hope so!
\ALineAgain
This is sort of fun. 

Can we reference equations by section? Try (\ref{firsteqn}) and (\ref{myeqn}).

\end{document}

答案1

在此处输入图片描述

有多个段落是没有问题的,\intertext只是不能有一行\par或一个空行,\endgraf但是可以:

\documentclass{article}
\usepackage{amsmath}

\def\a{One two three four. }
\def\b{\a\a\a\a}
\def\stuff{\b\b}
\begin{document}

\begin{align}
1&=222\\
\intertext{%
para 1 \stuff
\endgraf
Followed by para 2 \stuff}
33&=44\\
555&=6
\end{align}

\end{document}

相关内容