我希望a
拥有b
自己的方程式编号,同时保持multline
提供的整体布局。这可能吗?
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{multline}
a \\
b \\
c
\end{multline}
\end{document}
答案1
这也许不能完成所有的检查multline
,但可能足以满足您的目的:
\documentclass{article}
\usepackage{amsmath}
\usepackage{environ}
\usepackage{xparse}
\ExplSyntaxOn
\NewEnviron{nmultline}{%
\seq_set_split:NnV \l_nmultline_contents_seq { \\ } \BODY
\seq_pop_left:NN \l_nmultline_contents_seq \l_nmultline_first_tl
\seq_pop_right:NN \l_nmultline_contents_seq \l_nmultline_last_tl
\begin{gather}
\makebox[\dim_eval:n{\displaywidth-4em}][l]{$\displaystyle \l_nmultline_first_tl$} \\
\seq_use:Nn \l_nmultline_contents_seq { \\ }
\seq_if_empty:NF \l_nmultline_contents_seq { \\ }
\makebox[\dim_eval:n{\displaywidth-4em}][r]{$\displaystyle \l_nmultline_last_tl$}
\end{gather}
}
\seq_new:N \l_nmultline_contents_seq
\tl_new:N \l_nmultline_first_tl
\tl_new:N \l_nmultline_last_tl
\ExplSyntaxOff
\begin{document}
For comparison, first four rows
\begin{multline}
a \\
b \\
c \\
d
\end{multline}
and then two rows
\begin{multline}
a \\
b
\end{multline}
Now numbered:
\begin{nmultline}
a\label{a} \\
b\label{b} \\
c\label{c} \\
d\label{d}
\end{nmultline}
References: \eqref{a}, \eqref{c}, \eqref{bb}
\begin{nmultline}
a\label{aa} \\
b\label{bb}
\end{nmultline}
\end{document}
答案2
根据@egreg的回答,我得出了以下结论。它基本上定义了\gatherleft
与\gatherright
间距一致的命令\multline
,即使方程编号(包括标签)的长度不同。
它还适用于不同的字体大小,因此它们20pt
似乎相当稳定。如果有人知道它们对应的是什么,我很乐意相应地修改我的答案。
\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
% Left-/right-aligned lines in gather, with spacing consistent with multline.
% Limitations: \tag{...}, if used, has to come BEFORE corresponding \gatherleft or \gatherright
\makeatletter
\newlength{\gatherlabelwidth}
\newcommand{\gatherbox}[2]{
\settowidth{\gatherlabelwidth}{%
\iftag@%
\df@tag%
\else%
\stepcounter{equation}%
\print@eqnum%
\addtocounter{equation}{-1}%
\fi%
}
\makebox[\displaywidth - \gatherlabelwidth - 20pt][#1]{$\displaystyle #2$}
}
\makeatother
\newcommand{\gatherleft}[1]{\gatherbox{l}{#1}}
\newcommand{\gatherright}[1]{\gatherbox{r}{#1}}
% for this MWE only:
\newcommand{\reset}{
\setbox0=\vtop{\begin{multline}a\\b\\c\end{multline}}
\setlength{\mytempheight}{\ht0}
\addtolength{\mytempheight}{\dp0}
\color{red}\vspace*{-\mytempheight}\vspace*{-0.5\baselineskip}}
\usepackage{color}
\newlength{\mytempheight}
\def\countervalue{0}
\newif\ifusetag
\begin{document}
% Test some variations by uncommenting any line:
% \tiny
% \LARGE
% \def\countervalue{6}
% \def\countervalue{7}
% \def\countervalue{8}
% \def\countervalue{9}
% \def\countervalue{96}
% \def\countervalue{97}
% \def\countervalue{98}
% \def\countervalue{99}
% \usetagtrue
This is typeset with multline:
\setcounter{equation}{\countervalue}\stepcounter{equation}\stepcounter{equation}
\begin{multline}
a\\b\\c
\ifusetag
\tag{my tag!}
\else\fi
\end{multline}
\reset
This is typeset with gather:
\setcounter{equation}{\countervalue}
\begin{gather}
\gatherleft{a} \\
b \\
\ifusetag
\tag{my tag!}
\else\fi
\gatherright{c}
\end{gather}
\end{document}