Positioning – Adjusting the Horizontal Position of Equation Tags

amsmathpositioningtags

Both LaTeX and amsmath put tags aligned at right margin (in reqno mode by default), or aligned at left margin (in leqno mode).

I'd like a document where is posible that tags are separated of the margin by a fixed distance to say something like \tagmarginsep whether i use leqno or reqno mode.

Example

\documentclass{article}
\usepackage[width=0.7\textwidth,showframe]{geometry} % only for ajusting width and show margins
\usepackage{amsmath}
%---------------------------------------
% Switch between `leqno` and `reqno` mode in the same document
\makeatletter
\newcommand{\leqnomode}{\tagsleft@true\let\veqno\@@leqno}
\newcommand{\reqnomode}{\tagsleft@false\let\veqno\@@eqno}
\makeatother
%---------------------------------------
\newlength{\tagmarginsep} % Distance required
%\setlength{\tagmarginsep}{1cm} % For example
%---------------------------------------
\begin{document}

\vspace*{2ex}
\noindent This equation is in \texttt{reqno} mode (by default)
\begin{equation}
x=y
\end{equation}
and the next equation, number \eqref{eq2}, is in \texttt{leqno} mode.
\leqnomode
\begin{equation}\label{eq2}
a=b
\end{equation}

\end{document}

This gets something like

enter image description here

However i'd like something like

enter image description here

where the length of the red line(obviously without to draw this line) must be the separation between tag and margin controlled by \tagmarginsep. Is this possible for all (or some) numbered (or tagged) equations?

Best Answer

You can change \displaywidth and/or \displayindent:

\documentclass[]{article}
\usepackage[width=0.7\textwidth,showframe]{geometry} % only for ajusting width and show margins
\usepackage{amsmath}

%---------------------------------------
% Switch between `leqno` and `reqno` mode in the same document
\makeatletter
\newcommand{\leqnomode}{\tagsleft@true\let\veqno\@@leqno}
\newcommand{\reqnomode}{\tagsleft@false\let\veqno\@@eqno}

\makeatother
%---------------------------------------
\newlength{\tagmarginsep} % Distance required
\setlength{\tagmarginsep}{1cm} % For example

%---------------------------------------
\begin{document}\makeatletter 

\everydisplay{\displayindent=\tagmarginsep \displaywidth=\dimexpr\linewidth-2\tagmarginsep}
\vspace*{2ex}
\noindent This equation is in \texttt{reqno} mode (by default)
\begin{equation}
x=y
\end{equation}
and the next equation, number \eqref{eq2}, is in \texttt{leqno} mode.
\leqnomode
\begin{equation}\label{eq2}
a=b
\end{equation}

\end{document}

enter image description here

Related Question