3

I would like a and b to have an equation number of their own, while maintaining the overall layout that multline offers. Is that possible?

\documentclass{article}
\usepackage{amsmath}
\begin{document}
    \begin{multline}
    a \\
    b \\
    c
    \end{multline}
\end{document}
6
  • By default, all three lines have an equation number. What do you mean, exactly?
    – Bernard
    Jul 15, 2016 at 18:47
  • 1
    @Bernard I believe this is not true for multline. The manual says "Like equation, multline has only a single equation number".
    – bers
    Jul 15, 2016 at 18:49
  • 1
    what you probably want in a situation like this is gather. Jul 15, 2016 at 18:51
  • @barbarabeeton Yes, "like" gather, "while maintaining the overall layout that multline offers".
    – bers
    Jul 15, 2016 at 18:52
  • 1
    the \shoveleft and \shoveright commands pfovided by mathtools only work with multlined (which is the "internal" equivalent of multline'), so they're no help. the only suggestion i can make offhand, then, is to add large \hspace*s to adjust the positioning of individual lines. requesting extending the applicability of the \shove...` commands seems not unreasonable. Jul 15, 2016 at 18:59

2 Answers 2

2

This maybe doesn't all the checks as in multline, but might be sufficient for your purposes:

\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}

enter image description here

2
  • Thanks, this looks exactly like what I was looking for. Spacing is not perfectly identical, though - nmultline contents seems to be set a little farther away from both left and right page limits. Probably due to some space around the \makeboxes, because I could not fix it by removing all white space from your MWE.
    – bers
    Jul 17, 2016 at 23:10
  • Or maybe 4em used in \displaywidth-4em is just an imperfect approximation. 20pt looks pretty good to me (or not, that messes with the equation numbers for the second line).
    – bers
    Jul 17, 2016 at 23:16
1

Based on @egreg's answer, this is what I came up with. It basically defines \gatherleft and \gatherright commands that are consistent in spacing with \multline, even with varying lengths of equation numbers (including tags).

It also works with different font sizes, so the 20pt seem to be pretty constant. If anyone knows what those correspond to, I would be happy to modify my answer accordingly.

\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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .