# How to move the equation numbers to bottom lines?

\documentclass[preview,border=12pt,varwidth]{standalone}
\usepackage[a4paper,margin=1cm]{geometry}
\usepackage{mathtools}
\begin{document}
\abovedisplayskip=0pt\relax
\begin{align}
\begin{multlined}[b][7cm]
\framebox[5cm]{Top LHS}\\
\framebox[5cm]{Middle LHS}\\
\framebox[5cm]{Bottom LHS}
\end{multlined}
&= \begin{multlined}[t][7cm]
\framebox[5cm]{Top RHS 1}\\
\framebox[5cm]{Middle RHS 1}\\
\framebox[5cm]{Bottom RHS 1}
\end{multlined}\\
&= \begin{multlined}[t][7cm]
\framebox[5cm]{Top RHS 2}\\
\framebox[5cm]{Middle RHS 2}\\
\framebox[5cm]{Bottom RHS 2}
\end{multlined}
\end{align}
\end{document}

-

Usually the baseline of the equation number is aligned with the base line of the equation. The multlined with option t is just a box with a large depth.

You want to move the equation number down to the "bottom line", but this is not well defined:

• An equation can have several multlined environments with different bottom base lines.
• In the question the lines are boxed. Thus the baseline or depth of the equation number can be aligned with the bottom rule or maximum depth of the equation or the base line of the deepest element.
• The bottom line could be the bottom line of \substack, used as subscript of an integral/sum operator.

Therefore I think, it depends on the equation, where the best place for the equation number is. The following example defines \tagvpos that sets a position label to mark the vertical position, where the equation tag should go:

• It is implemented for the measuring environments of package amsmath (e.g. gather, align, not equation).
• It uses package zref-savepos for the position label that uses a feature of pdfTeX that is available in both modes PDF and DVI and that is also supported by XeTeX and LuaTeX.
• Package amsmath has the feature that it moves the equation tag down, if the equation is too wide. In the latter case, the equation number is not additionally moved via \tagvpos.

Example file:

\documentclass{article}
\usepackage[
a4paper,
hmargin=48mm,
]{geometry}
\usepackage{mathtools}

\usepackage{zref-savepos}
\makeatletter
\@ifdefinable\saved@make@display@tag{%
\@ifdefinable\saved@maketag@@@{%
\@ifdefinable\tagvpos@label{%
\newif\iftagvpos@shifttag@
\global\tagvpos@shifttag@true
}%
\newcommand*{\tagvpos@reset}{%
\global\let\tagvpos@label\relax
\global\tagvpos@shifttag@false
}%
\let\saved@make@display@tag\make@display@tag
\def\make@display@tag{%
\ifmeasuring@
\tagvpos@reset
\else
\let\saved@maketag@@@\maketag@@@
\def\maketag@@@##1{%
\ifx\tagvpos@label\relax
\tagvpos@reset
\expandafter\@firstoftwo
\else
\zref@refused{\tagvpos@label a}%
\zref@refused{\tagvpos@label b}%
\begingroup
\let\@auxout=\@mainaux
\zsaveposy{\tagvpos@label b}%
\endgroup
\ifx\tag@shifts\@empty
\else
\if1\shift@tag\row@\relax
\global\tagvpos@shifttag@true
\fi
\fi
\iftagvpos@shifttag@
\tagvpos@reset
\expandafter\expandafter\expandafter\@firstoftwo
\else
\expandafter\expandafter\expandafter\@secondoftwo
\fi
\fi
{%
\saved@maketag@@@{##1}%
}{%
\raisebox{%
\dimexpr\zposy{\tagvpos@label a}sp-\zposy{\tagvpos@label b}sp\relax
}{\saved@maketag@@@{##1}}%
\tagvpos@reset
}%
}%
\fi
\saved@make@display@tag
}%
\begingroup
\newcounter{tagvpos}
\endgroup
\renewcommand*{\thetagvpos}{tagvpos\number\value{tagvpos}}
\newcommand*{\tagvpos}{%
\ifmeasuring@
\else
\stepcounter{tagvpos}%
\xdef\tagvpos@label{\thetagvpos}%
\begingroup
\let\@auxout=\@mainaux
\zsaveposy{\tagvpos@label a}%
\endgroup
\fi
}%
}%
}%
}
\makeatother

% Testing

\usepackage{color}
\newcommand*{\tagmark}{%
\begingroup
\sbox0{$\vcenter{}$}%
\raisebox{-\ht0}[0pt][0pt]{\textcolor{red}{$\,\mapsto$}}%
\endgroup
}

\begin{document}

\begin{gather}
\text{environment \texttt{gather}}\nonumber
\\
\hspace{.75\linewidth}1 = 1
\\
\hspace{.75\linewidth}0.5 = \frac{1}{2\tagmark\tagvpos}\\
\tag{a}
\label{a}
\hspace{.75\linewidth}\ref{a} = \frac{\eqref{a}\tagmark\tagvpos}{1}
\\
\hspace{\linewidth}
\llap{%
$\dots$
\begin{tabular}[t]{@{}r@{}}
very long\\equation\tagmark\tagvpos
\end{tabular}%
}
\end{gather}

\begin{align}
\text{environment \texttt{align}} &+ \text{\texttt{multlined}}\nonumber\\
\begin{multlined}[b][5cm]
\framebox[3cm]{Top LHS}\\
\framebox[3cm]{Middle LHS}\\
\framebox[3cm]{Bottom LHS}
\end{multlined}
&= \begin{multlined}[t][5cm]
\framebox[3cm]{Top RHS 1}\\
\framebox[3cm]{Middle RHS 1}\\
\framebox[3cm]{Bottom RHS 1\tagmark\tagvpos}
\end{multlined}\\
&= \begin{multlined}[t][5cm]
\framebox[3cm]{Top RHS 2}\\
\framebox[3cm]{Middle RHS 2}\\
\framebox[3cm]{Bottom RHS 2\tagmark\tagvpos}
\end{multlined}
\end{align}

\begin{align}
\hspace{\linewidth}
\llap{%
$\dots$
\begin{tabular}[t]{@{}r@{}}
very long\\equation\tagmark\tagvpos
\end{tabular}%
}
\end{align}
\end{document}


Remarks:

• The internal position labels are automatically named using a counter. The labels are written to the main .aux file only to keep the uniqueness of the label names, if \include files are involved (\let\@auxout\@mainaux). Also the counter for the label names is not reset in .aux files for \include files (this is the purpose of the local \let\@addtoreset\@gobbletwo right before \newcounter).

• Shift detection for too wide equations: Environment gather uses a switch, whereas align stores the shift state in a list for all rows.

-

For amsmath constructs you can use

\usepackage[tbtags]{amsmath}


and the equation numbers move to the bottom (or to the top if you are using left numbering) however that doesn't appear to work in mathtools except for the constructs that come from the underlying amsmath.

-
Actually this answer does not solve my problem. :-) –  stalking is prohibited Apr 18 '13 at 18:30
@Bugbusters not solve because you are using mathtools or for some other reason? –  David Carlisle Apr 18 '13 at 19:12
Because amsmath does not provide multlined as well. –  stalking is prohibited Apr 18 '13 at 19:18
@Bugbusters Yes I pinged Joseph to see if he wanted to add a tbtags option to mathtools to match:-) –  David Carlisle Apr 18 '13 at 20:06
Thank you for pinging. :-) –  stalking is prohibited Apr 18 '13 at 20:11

I had to cheat a bit with the layout of the page, but here is my solution.

Just use simple align commands, and provide the indent and numbering manually. It could look awkward when the lower lines have differnet width, though.

It looks to me that precise control with multlined seems difficult anyway.

\documentclass[preview,border=12pt,varwidth]{standalone}
\usepackage[a4paper,landscape]{geometry}
\usepackage{mathtools}
\begin{document}
\abovedisplayskip=0pt\relax
\begin{align}
\framebox[5cm]{Top LHS} \hspace{4cm} \nonumber \\
\framebox[5cm]{Middle LHS} \hspace{2cm} \nonumber \\
\framebox[5cm]{Bottom LHS}
&=
\framebox[5cm]{Top RHS 1} \nonumber \\
& \hphantom{=} \hspace{2cm}  \framebox[5cm]{Middle RHS 1} \nonumber \\
& \hphantom{=} \hspace{4cm}  \framebox[5cm]{Bottom RHS 1} \\
&=
\framebox[5cm]{Top RHS 2} \nonumber \\
& \hphantom{=} \hspace{2cm}  \framebox[5cm]{Middle RHS 2} \nonumber \\
& \hphantom{=} \hspace{4cm}  \framebox[5cm]{Bottom RHS 2}
\end{align}
\end{document}


-

Here's a stackengine solution, using the \abovebaseline macro, knowing that the equation number will appear on the baseline (aka "math axis").

If you didn't have a multi-numbered environment (that is, if your equation only had a single number), the solution would be quite simple: \abovebaseline[0pt]{your equation here} If your math doesnn't already end up in math mode, you may need a \stackMath once at the onset.

\documentclass[preview,border=12pt,varwidth]{standalone}
\usepackage[a4paper,margin=1cm]{geometry}
\usepackage{mathtools}
\usepackage{stackengine}
\begin{document}
\abovedisplayskip=0pt\relax
\begin{align}
\abovebaseline[2.5\baselineskip]{\begin{multlined}[b][7cm]
\framebox[5cm]{Top LHS}\\
\framebox[5cm]{Middle LHS}\\
\framebox[5cm]{Bottom LHS}
\end{multlined}}
&\abovebaseline[0pt]{ = \begin{multlined}[t][7cm]
\framebox[5cm]{Top RHS 1}\\
\framebox[5cm]{Middle RHS 1}\\
\framebox[5cm]{Bottom RHS 1}
\end{multlined}}\\
&\abovebaseline[0pt]{ = \begin{multlined}[t][7cm]
\framebox[5cm]{Top RHS 2}\\
\framebox[5cm]{Middle RHS 2}\\
\framebox[5cm]{Bottom RHS 2}
\end{multlined}}
\end{align}
\end{document}

-
Why do we need geometry here? –  stalking is prohibited Aug 23 '13 at 13:27
@PSTikZ Actually, it does seem to be needed. Not sure why. –  Steven B. Segletes Aug 23 '13 at 22:58