[Tex/LaTex] Equation number at the right of first line with multline

equationsmultlinenumbering

This is very similar to A vertically centered equation number on a multline environment, but the answers won't apply to my case it seems.

I have

\begin{multline}
X = \\
LOOOOOOOOOOOOOOOOOOOOOOOOOOONG
\end{multline}

and like how the output looks without a line number. Now I want to add a line number to the right, but the second line is too long. How do I put it in the first line (to the right!)?

I know about \raisetag, but I would prefer an exact solution. My second line has a non-trivial height.

Edit: I should add that LOOOOOOOOOONG is nearly as long as my text width.

Edit: This is a more appropriate example:

\begin{multline}
X = \\
\framebox[\linewidth]{LONG}
\end{multline}

Edit: Once again a more elaborate example to show that egreg's answer does not answer my question. My use case is an integral expression that I do not want to break. It does not matter how it looks or what its contents is. Its line is pretty damn close to the available linewidth.

\documentclass{article}
\usepackage{mathtools}
\usepackage[showframe]{geometry}
\setlength{\multlinegap}{0pt}
\begin{document}

This works fine:
\begin{equation}
\begin{multlined}[t]%
X = \\%
\framebox[\dimexpr.9\linewidth\relax]{some expression shorter than the next}%
\end{multlined}%
\end{equation}%


Note the equation number in this harder case:
\begin{equation}%
\begin{multlined}[t]%
    X = \\%
    \framebox[\dimexpr\linewidth-1.666666pt\relax]{long expression that I do not want to break}%
\end{multlined}%
\end{equation}%

This solves the equation number problem, but messes up horizontal positioning. It actually goes over the right border:
\begin{equation}%
    \begin{multlined}[t]%
        X = \\%
        \mathmakebox[.9\width][l]{%
            \framebox[\dimexpr\linewidth-1.666666pt\relax]{long expression that I do not want to break}%
        }%
    \end{multlined}%
\end{equation}

\end{document}

Best Answer

You can use multlined from mathtools (that loads amsmath):

\documentclass{article}
\usepackage{mathtools}

\begin{document}
\begin{multline}
X =  \\
LOOOOOOOOOOOOOOOOOOOOOOOOOOONG
\end{multline}
\begin{equation}
\begin{multlined}[t][.9\displaywidth]
X =  \\
LOOOOOOOOOOOOOOOOOOOOOOOOOOONG
\end{multlined}
\end{equation}
\begin{equation}
\begin{multlined}[t]
X =  \\
LOOOOOOOOOOOOOOOOOOOOOOOOOOONG
\end{multlined}
\end{equation}
\end{document}

If the first line is short, I'd prefer the third option. But in my documents the number stays with the last line.

enter image description here

A different approach, for a really long line:

\documentclass{article}
\usepackage{mathtools}
\usepackage[showframe]{geometry}
\begin{document}

\begin{flalign}
& X= && \\
&&& \mathmakebox[0pt][r]{%
  \framebox[\displaywidth]{\dotfill long expression that I do not want to break\dotfill}
  \hspace{-1.8em}
}
\notag
\end{flalign}

\end{document}

You have to hide a the part that would overlap the space for the equation number

enter image description here

Related Question