[Tex/LaTex] rcl column alignment, no extra spaces, and \tag{} for each line

equationshorizontal alignmenttag

I'm looking for a way to place some text flushed to the right margin (like \tag*{…} does) at the end of each line of an equation. The equation has multiple columns, and I need to control the alignment (right, center or left) of each column. Furthermore, I don't want the environment to add extra space before the first column, after the last column or between columns.

I tried the following, which does not work because only a single \tag{…} is allowed for the whole equation.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\begin{array}{@{}r@{}c@{}l@{}}
  a&bbbbb&c \tag*{a, b and c} \\
  x&y&z    \tag*{other stuff}\\
\end{array}
\]
\end{document}

Screenshot of the desired outcome.

It would be cool if I could also do this for sub-cases (lines after a big opening brace), like numcases does (but numcases does not support \tag, and adds extra spaces everywhere).

Things I tried (after browsing through quite a few questions here):

  • equationarray from the eqnarray package looks promissing, but it does not support the \tag{…} command, only \notag (I tried and failed to manually call the internals of what \tag{…} does). align adds extra space between
  • align and empheq do not support rcl column specifications and add extra space
  • alignat* has everything except rcl column specification (it is hardcoded to be rlrlrl…)

Right now my best bet is to put a marker with tikz and draw the label as an overlay (I am not extremely interested in precise \label/\ref references, I can make all labels point to the whole multi-line equation if needed, so drawing with tikz is a crude, but viable solution).

Best Answer

You can abuse IEEEtrantools (but I recommend not pushing material that belongs in the equation to the right margin, which should be reserved for reference marks or numbers).

Note that you are responsible for avoding overlaps.

\documentclass{article}
\usepackage{amsmath}
\usepackage{IEEEtrantools}
\usepackage{showframe}

\begin{document}

\begin{IEEEeqnarray*}{r-c-l+r-}
a&bbbbb&c &\makebox[0pt][r]{a, b and c} \\
x&y&z     &\makebox[0pt][r]{other stuff}
\end{IEEEeqnarray*}

\begin{equation}
abbbbbc
\end{equation}

\end{document}

enter image description here

Original answer for reference

\documentclass{article}
\usepackage{amsmath}
\usepackage{IEEEtrantools}

\renewcommand\theIEEEsubequationdis{\theIEEEsubequation}
\newcommand{\IEEEtag}[1]{%
  \IEEEyessubnumber
  \gdef\theIEEEsubequation{#1}%
}

\begin{document}

\begin{IEEEeqnarray}{r-c-l}
a&bbbbb&c \IEEEtag{a, b and c} \\
x&y&z     \IEEEtag{other stuff}
\end{IEEEeqnarray}

\begin{equation} % just for checking the number has not advanced
a
\end{equation}

\end{document}

enter image description here

Related Question