2

I am using pdfLaTeX. If no packages are used, then, in displayed equations, the line numbers are flushed right. But if I want them to be a certain distance, say 0.35em, from the right margin, I can accomplish that by redefining \@eqnnum like this:

\makeatletter
\def\@eqnnum{{\normalfont \normalcolor (\theequation)\hspace{0.35em}}}
\makeatother

However, if amsmath is used, then the above has no effect.

Suppose I am using amsmath. How can I insert an arbitrary but fixed distance between equation numbers and the right margin? The solution should insert the same distance for all displayed math environments (equation, multline, align, etc.).

2

2 Answers 2

4

It's really unfortunate that amsmath uses the same internal macro both for the equation number and \eqref, but you can recycle https://tex.stackexchange.com/a/261647/4427

\documentclass{article}
\usepackage{amsmath}

\makeatletter
% detach \eqref and \tag making
\renewcommand{\eqref}[1]{\textup{\eqreftagform@{\ref{#1}}}}
\let\eqreftagform@\tagform@

\def\tagform@#1{%
  \maketag@@@{(\ignorespaces#1\unskip\@@italiccorr)\quad}%
}
\makeatother

\begin{document}

\noindent X\dotfill X
\begin{equation}\label{test}
1=1
\end{equation}
X\dotfill X

Now we want \eqref{test} and that the space is right.

\end{document}

Instead of \quad you can use \hspace with whatever length you prefer.

enter image description here

4

I wouldn't manipulate low-level TeX macros directly, as doing so could have unintended and unfortunate consequences. Instead, I'd pursue a high-level approach, e.g., by employing the \newtagform and \usetagform macros of the mathtools package. One reason I think this is a wise thing to do is that it makes it very easy to switch back and forth among various equation tag forms.

To create cross-references to the equations in questions, I suggest you load the cleveref package and employ its \cref and \labelcref macros, in lieu of the \eqref macro that's provided by the amsmath package. A big advantage of \cref and \labelcref is that they can take multiple arguments, not just one at a time.

enter image description here

\documentclass{article} % or some other suitable document class
\usepackage{showframe}  % to indicate edges of text block

\usepackage{mathtools}  % for \newtagform and \usetagform macros
\newtagform{space}{(}{)\hspace{0.35em}}

\setlength\textwidth{3in} % just for this example

\usepackage[noabbrev]{cleveref} % <-- for \cref macro
\begin{document}
\usetagform{space}
\begin{equation}\label{eq:A} 1+1=2 \end{equation}
\begin{equation}\label{eq:B} 2+2=4 \end{equation}
A cross-reference to \cref{eq:A,eq:B}.

\usetagform{default} % revert to default tag form
\begin{equation}\label{eq:C} 3+3=6 \end{equation}

\end{document}
2
  • This has an unfortunate side effect: there is extra space added after equation number when it is referred to in text. For example, Equation~\eqref{EqnExample}, ends up looking like this: Equation (31) , (note the extra space between ( and ,). Commented Mar 2, 2022 at 15:14
  • 1
    @linguisticturn - I've updated my answer to address your concern. Basically, I suggest you not use \eqref. Instead, I suggest you load the cleveref package and employ its user-level macros \cref, \Cref, and \labelcref. For instance, you could replace Equation~\eqref{EqnExample}, with \Cref{EqnExample},.
    – Mico
    Commented Mar 2, 2022 at 16:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .