# Equation number at the right of first line with multline

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{multlined}[t]% X = \\% \framebox[\dimexpr.9\linewidth\relax]{some expression shorter than the next}% \end{multlined}%$$%

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

This solves the equation number problem, but messes up horizontal positioning. It actually goes over the right border:
$$% \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{document}


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

\documentclass{article}
\usepackage{mathtools}

\begin{document}
\begin{multline}
X =  \\
LOOOOOOOOOOOOOOOOOOOOOOOOOOONG
\end{multline}
$$\begin{multlined}[t][.9\displaywidth] X = \\ LOOOOOOOOOOOOOOOOOOOOOOOOOOONG \end{multlined}$$
$$\begin{multlined}[t] X = \\ LOOOOOOOOOOOOOOOOOOOOOOOOOOONG \end{multlined}$$
\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.

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

• Thanks, that I nice idea. I did not know about [t]. However, when using LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG instead of LOOOOOOOOOOOOOOOOOOOOOOOOOOONG, the number jumps to a third line of the equation, although there is enough space on the first line. It depends on the length of the second line and \textwidth - I edited my question accordingly. – bers Feb 3 '15 at 22:37
• @bers Yes, of course; if a line is too long, the equation number is shifted down and multlined is just a single block. It would be shifted also with multiline. – egreg Feb 3 '15 at 22:59
• You got it. Now my second line happens to be too long, so I still need a solution :) My first line is not too long, so the number should always fit. Yes, multline has the same problem as your solution, but this does not mean 1) that this is what I want, nor 2) that this is how it has to be. I want a short first line, left-aligned, with an equation number on the right; and a very long second line, potentially filling the line, right-aligned, with no equation number. – bers Feb 3 '15 at 23:48
• @bers In tough cases, you can hide a portion of the last line by using something like \mathmakebox[.9\width][l]{...}. No automatic solution, I'm afraid. – egreg Feb 3 '15 at 23:49
• \mathmakebox[.5\width][c]{\framebox[\linewidth]{LONG}} looks like it's working. I'll try further with that, thanks so far! – bers Feb 4 '15 at 0:38

How can I use an align environment flush right? and Use flalign or alignat or align or similar environment to align to the left helped me come up with this (which I am quite happy with):

\begin{gather}
\begin{flalign}
& X = &
\end{flalign}\\
\begin{flalign*}
&& LOOOOOOOOOOOOOOOOOOOOOOOOOOONG
\end{flalign*}
\end{gather}


Edit: Putting everything together what egreg proposed (in particuar, mathmakebox, this is what I came up with.

\begin{align}
& #1 \\
& \mathmakebox[\displaywidth][r]{#2}\notag
\end{align}


Actually pretty simple. I doubt it can be much easier than this. egreg's solution has the drawback of not working with unknown tag widths, and I have not found how to get them from amsmath.

• The vertical spacing is not optimal, so if anyone finds an alternative the spacing of which is closer to the multline solution, I'd be happy to accept that. – bers Feb 3 '15 at 22:49
• Just use one flalign environment, with \notag in the line you don't want the number in. – egreg Feb 4 '15 at 16:30
• Thanks. I have tried that before, but I was unable to get the alignment right then. I want first line flush-left, second flush-right, no matter how long they are. Having the two in a single flalign makes that the two lines cannot "overlap". Remember, the second line is long. – bers Feb 4 '15 at 16:37
• That's why I asked for a real case. – egreg Feb 4 '15 at 16:38
• There is one in my MWE, the second one. – bers Feb 4 '15 at 16:39