重温:“如何根据奇数页还是偶数页将公式编号放在左边或右边”

重温:“如何根据奇数页还是偶数页将公式编号放在左边或右边”

参考: 如何根据奇数页还是偶数页将公式编号放在左侧或右侧

最初的问题/要求是,偶数页的公式编号位于右侧,奇数页的公式编号位于左侧;即靠近内页边距。``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}

我不知道如何解决这个align问题…… 在此处输入图片描述

相关内容