# Right align equations relative to maximum length of equation-number

Please have a look at this minimal example ...

\documentclass{article}
\usepackage{amsmath}
\numberwithin{equation}{section}
\usepackage{showframe} % only for demo

\begin{document}

\section{section 1}
\begin{flalign}
&&\begin{split}
a = b \\
b = c + d + e
\end{split}
\end{flalign}

\section{section 2}
\setcounter{equation}{1234}
\begin{flalign}
&&\begin{split}
a = b \\
b = c + d + e
\end{split}
\end{flalign}

\end{document}


It generates this document ...

My question is ... The equation in section 1 is positioned right of the equation in section 2. This is a result of the length of the equation-number. How to align the right side of the equation vertically? Or, how to make the right alignment depend on the widest equation-number?

I'm not sure what's the purpose of this unusual format.

Here's a way, with a modification of code from https://tex.stackexchange.com/a/240341/4427

\documentclass{article}
\usepackage{amsmath}
\usepackage{etoolbox}
\usepackage{lipsum}

\numberwithin{equation}{section}
\usepackage{showframe} % only for demo

\makeatletter
% detach \eqref processing from \tag processing
\let\tagform@ref\tagform@
\let\maketag@@@ref\maketag@@@
\patchcmd{\eqref}{\tagform@}{\tagform@ref}{}{}
\patchcmd{\tagform@ref}{\maketag@@@}{\maketag@@@ref}{}{}
% redefine \maketag@@@
\def\maketag@@@#1{\makebox[4pc][r]{\m@th\normalfont#1}}
\makeatother

\begin{document}

\section{section 1}
\begin{flalign}
&&\begin{aligned}
a = b \\
b = c + d + e
\end{aligned}
\end{flalign}

\section{section 2}
\setcounter{equation}{1234}
\begin{flalign}
&&\begin{aligned}
a = b \\
b = c + d + e
\end{aligned}
\end{flalign}

\end{document}


Adjust the 4pc amount to suit. With some more work it could be made automatic. I wouldn't use split for this, but aligned.

• Thank you! You say it's an unusual format. What would you suggest? Do you think left- or centered-aligned is better? Why? – user100924 Mar 18 '16 at 9:20
• @user100924 Can you point to some book where that format is used? – egreg Mar 18 '16 at 9:20
• Probably not, but that doesn't answer the question why it's not suitable. – user100924 Mar 18 '16 at 10:41
• @user100924 I said unusual. I'm not the one who should justify an opinion. – egreg Mar 18 '16 at 10:46
• Probably not, what's the better alternative? – user100924 Mar 18 '16 at 13:22