并放LaTeX
amsmath
标签与右边距对齐(reqno
默认模式下),或与左边距对齐(leqno
模式下)。
我想要一份文件,其中可能标签与边缘之间有固定距离,用来表示\tagmarginsep
我是否使用leqno
或reqno
模式。
例子
\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}
这得到类似
不过我想要的是
其中的长度红线(显然没有画这条线)必须是之间的分离标签和利润由 控制\tagmarginsep
。对于所有(或部分)编号(或标记)方程式,这是否可行?
答案1
您可以更改 \displaywidth 和/或 \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}
答案2
通过amsmath
重新定义,这成为可能\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}