最初的问题/要求是,偶数页的公式编号位于右侧,奇数页的公式编号位于左侧;即靠近内页边距。``Jagath'' 给出了一个很好的答案,但解决方案对于我这个小脑袋来说大多是难以理解的。我尝试切换奇数和偶数、左和右,但我无法让公式编号出现在或靠近外边距。
\documentclass{book}
\usepackage{lipsum}
\usepackage{amsmath}
\usepackage{bm}
\newcommand{\Cdot}{\bm{\cdot}}
% Inner margin numbering (I want outer margin numbering)
\makeatletter
\def\mathlabel#1{\@bsphack
\protected@write\@auxout{}%
{\string\newlabel{#1}{{\@currentlabel}{\thepage}}}%
\@esphack}
\def\eqnWrite{\@bsphack
\protected@write\@auxout{}%
{\string\EqnStat{\theequation}{\thepage}}%
\@esphack}%
\def\EqnStat#1#2{%
\expandafter\gdef\csname eqn@#1\endcsname{#2}%
}
\newcommand\@reqnnum{\hb@[email protected]\p@{}%
\rlap{\normalfont\normalcolor%
\hskip -\displaywidth(\theequation)}}
\def\equation{\let\mathlabel\label$$\refstepcounter{equation}}
\def\endequation{\eqno\eqnWrite\@ifundefined{eqn@\theequation}{\hbox{\@eqnnum}}%%
{\expandafter\ifodd\csname eqn@\theequation\endcsname\hbox{\@reqnnum}%
\else\hbox{\@eqnnum}\fi}$$\@ignoretrue}
\def\@@eqncr{\let\reserved@a\relax%
\ifcase\@eqcnt \def\reserved@a{& & &}\or \def\reserved@a{& &}%
\or \def\reserved@a{&}\else%
\let\reserved@a\@empty%
\@latex@error{Too many columns in eqnarray environment}\@ehc\fi%
\reserved@a \if@eqnsw\eqnWrite%
\@ifundefined{eqn@\theequation}{\@eqnnum}%
{\expandafter\ifodd\csname eqn@\theequation\endcsname\@reqnnum%
\else\@eqnnum\fi}\stepcounter{equation}\fi%
\global\@eqnswtrue\global\@eqcnt\z@\cr}
\makeatother
\begin{document}
\lipsum[1]
\begin{equation}
E^2 = (mc^2)^2 + (pc)^2
\end{equation}
\lipsum[2]
\begin{subequations}
\begin{equation}
A = B + C
\end{equation}
\begin{equation}
B = C + D
\end{equation}
\begin{equation}
D = E + F
\end{equation}
\end{subequations}
\begin{equation}
\begin{array}{|cc|}
d & e \\
f & g
\end{array}
\end{equation}
\begin{align}
F &= A\times B\qquad\text{ ALIGN FAILS!}\\
G\Cdot D &= H\Cdot P\times Q + B\Cdot V
\end{align}
\lipsum[3-4]
\begin{equation}
E^2 = (mc^2)^2 + (pc)^2
\end{equation}
\lipsum[2]
\begin{subequations}
\begin{equation}
A = B + C
\end{equation}
\begin{equation}
B = C + D
\end{equation}
\begin{equation}
D = E + F
\end{equation}
\end{subequations}
\begin{equation}
\begin{array}{|cc|}
d & e \\
f & g
\end{array}
\end{equation}
\begin{align}
F &= A\times B\\
G + D &= P\times Q + B
\end{align}
\end{document}
答案1
\ifodd
代码中有两个测试:您必须在它们的定义中\@reqnnum
切换。\@eqnnum
\documentclass[twoside]{book}
\usepackage{lipsum}
\usepackage{amsmath}
\usepackage{bm}
\newcommand{\Cdot}{\bm{\cdot}}
% Inner margin numbering (I want outer margin numbering)
\makeatletter
\def\mathlabel#1{\@bsphack
\protected@write\@auxout{}%
{\string\newlabel{#1}{{\@currentlabel}{\thepage}}}%
\@esphack}
\def\eqnWrite{\@bsphack
\protected@write\@auxout{}%
{\string\EqnStat{\theequation}{\thepage}}%
\@esphack}%
\def\EqnStat#1#2{%
\expandafter\gdef\csname eqn@#1\endcsname{#2}%
}
\newcommand\@reqnnum{\hb@[email protected]\p@{}%
\rlap{\normalfont\normalcolor%
\hskip -\displaywidth(\theequation)}}
\def\equation{\let\mathlabel\label$$\refstepcounter{equation}}
\def\endequation{\eqno\eqnWrite\@ifundefined{eqn@\theequation}{\hbox{\@eqnnum}}%%
{\expandafter\ifodd\csname eqn@\theequation\endcsname\hbox{\@eqnnum}% <- Here
\else\hbox{\@reqnnum}\fi}$$\@ignoretrue}
\def\@@eqncr{\let\reserved@a\relax%
\ifcase\@eqcnt \def\reserved@a{& & &}\or \def\reserved@a{& &}%
\or \def\reserved@a{&}\else%
\let\reserved@a\@empty%
\@latex@error{Too many columns in eqnarray environment}\@ehc\fi%
\reserved@a \if@eqnsw\eqnWrite%
\@ifundefined{eqn@\theequation}{\@eqnnum}%
{\expandafter\ifodd\csname eqn@\theequation\endcsname\@eqnnum% <- Here
\else\@reqnnum\fi}\stepcounter{equation}\fi%
\global\@eqnswtrue\global\@eqcnt\z@\cr}
\makeatother
\begin{document}
\lipsum[1]
\begin{equation}
E^2 = (mc^2)^2 + (pc)^2
\end{equation}
\lipsum[2]
\begin{subequations}
\begin{equation}
A = B + C
\end{equation}
\begin{equation}
B = C + D
\end{equation}
\begin{equation}
D = E + F
\end{equation}
\end{subequations}
\begin{equation}
\begin{array}{|cc|}
d & e \\
f & g
\end{array}
\end{equation}
\begin{align}
F &= A\times B\qquad\text{ ALIGN FAILS!}\\
G\Cdot D &= H\Cdot P\times Q + B\Cdot V
\end{align}
\lipsum[3-4]
\begin{equation}
E^2 = (mc^2)^2 + (pc)^2
\end{equation}
\lipsum[2]
\begin{subequations}
\begin{equation}
A = B + C
\end{equation}
\begin{equation}
B = C + D
\end{equation}
\begin{equation}
D = E + F
\end{equation}
\end{subequations}
\begin{equation}
\begin{array}{|cc|}
d & e \\
f & g
\end{array}
\end{equation}
\begin{align}
F &= A\times B\\
G + D &= P\times Q + B
\end{align}
\end{document}