3

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?

  • and what you will do at long equation? here usually people ask how to fit equation in text width space :) – Zarko Aug 12 '17 at 17:38
  • What should happen if the numbers gets larger, e.g. (10)? – Ulrike Fischer Aug 12 '17 at 17:38
  • @UlrikeFischer, if the numbers are larger they must extend toward the center of the page as is done by default but keeping the separation of the margin fixed. – skpblack Aug 12 '17 at 17:58
3

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

| improve this answer | |
0

With amsmath this becomes possible by redefining \tagform@.

\documentclass[]{article}

\usepackage{amsmath}
\usepackage[showframe]{geometry}

\newdimen\tagmarginsep\tagmarginsep=10mm

\makeatletter
\newcommand{\leqnomode}{\tagsleft@true\let\veqno\@@leqno}
\newcommand{\reqnomode}{\tagsleft@false\let\veqno\@@eqno}
\def\tagform@#1{%
    \iftagsleft@\hspace{\tagmarginsep}\fi%
    \maketag@@@{(\ignorespaces#1\unskip\@@italiccorr)}%
    \iftagsleft@\else\hspace{\tagmarginsep}\fi}
%fixing eqref:
\renewcommand{\eqref}[1]{\textup {\maketag@@@ {(\ignorespaces\ref {#1}\unskip\@@italiccorr)}}}
\makeatother

\begin{document}
\begin{equation}
    e=mc^2
    \label{eq1}
\end{equation}
see \eqref{eq1} for yourself
\leqnomode
\begin{equation}
    e=mc^2
    \label{eq2}
\end{equation}
see \eqref{eq2} for yourself
\end{document}
| improve this answer | |
  • This won't work. It affects also references, add a label and try abc \eqref{test} xxx – Ulrike Fischer Aug 12 '17 at 17:50
  • This doesn't work leaving space at left when leqno option is loaded. Morever if i use a reference with \eqref{<label>} adds \hspace{...} at right of _equation. – skpblack Aug 12 '17 at 17:51
  • @UlrikeFischer I don't use \eqref myself (literally never did), but you're right, it doesn't work with it. – Skillmon likes topanswers.xyz Aug 12 '17 at 17:53
  • @skpblack the skipping for the leqno option is easy done (see edit), but the problem with \eqref persists. – Skillmon likes topanswers.xyz Aug 12 '17 at 17:54
  • @skpblack fixed \eqref see edit. – Skillmon likes topanswers.xyz Aug 12 '17 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.