\ref{ } 有问题(页边距中的公式编号)。还有垂直间距问题

\ref{ } 有问题(页边距中的公式编号)。还有垂直间距问题

我正在使用一个宏,它接受equation,在其后放置*,隐藏方程编号,然后使用\stepcounter{equation}\marginpar{\centering(\theequation)}并将方程编号放在外边距中。但现在\ref{ }无法正常工作。垂直间距不对。如果您能帮助我,我将不胜感激。

\documentclass[twoside]{article}
  % You can adjust equation number location with \marginparwidth and/or \marginparsep
  \setlength{\marginparwidth}{0.5in}
  \usepackage{comment,layout}
  \usepackage{amsmath}
  %  \usepackage{marginnote}
  \numberwithin{equation}{section}
  \usepackage{bm}
  \newcommand{\Cdot}{\bm\cdot}
  % YOU CAN PROBABLY IGNORE THIS LAYOUT STUFF..
  % ------- \layout -------------------------------------------------
  % You can change \layout output metric here..
  % in    = 1/72.27    = 0.01384
  % picas = 12/72.27   = 0.16604
  % bp    = 72/72.27   = 0.99626
  % mm    = 25.4/72.27 = 0.35146
  \makeatletter
    \renewcommand*{\lay@value}[2]{ % (stackexchange - egreg)
      \strip@pt\dimexpr0.01384\dimexpr\csname#2\endcsname\relax\,in %
                                 }
  \makeatother
  % -----------------------------------------------------------------
  % !!! HERE IT IS !!!...
  \newcommand{\MarginNum}[3]{
    \begin{#1*}    % #1 = equation, align, etc.
      #2\ #3       % #2 = body of equation, align, etc. #3 = \label{}
    \end{#1*}
    \vspace{-18.0pt}   % Fudge factor          % \vspace{-2.0\baselineskip}
    \stepcounter{equation}
    \marginpar{\centering(\theequation)}
    \vspace{3.0pt}     % Fudge factor          % \vspace{0.85\baselineskip}
                            }

  % Another version that doesn't work right either;
  \newcommand{\PMarginNum}[3]{
    \vspace{24pt}
    \marginpar{\begin{equation} \hphantom{\,} \end{equation}}
    \vspace{-18pt}
    \begin{#1*}   % #1 = equation, align, etc.
      #2\ #3       % #2 = body of equation, align, etc. #3 = \label{}
    \end{#1*}
   \vspace{-18pt}
                            }

  % Evolution of the fudge factors:
  % (-28,13) Bottom of 1
  % (-35,20) Top of 2
  % (-25,10) Below middle of 1
  % (-24, 9) Below middle
  % (-23, 8) At middle
  % ------------------------------------------------
  % \raggedbottom
  % \usepackage{showframe}
\begin{document}
  \setcounter{section}{4}
  \section{Trouble With \textbackslash ref\{ \}'ing (Equations Numbers In Margins). Also Vertical Spacing Issues}      %{Quam Numerare Tuum Digitos}

  \medskip
  Using <equation>:

  \MarginNum{equation}{E_1^2 = (mc^2)^2 + (p_1c)^2}{\label{E1}}
  \MarginNum{equation}{E_2^2 = (mc^2)^2 + (p_2c)^2}{\label{E2}}
  \MarginNum{equation}{E_3^2 = (mc^2)^2 + (p_3c)^2}{\label{E3}}
  \MarginNum{equation}{E_4^2 = (mc^2)^2 + (p_4c)^2}{\label{E4}}
  
  \noindent We reference the above equations (\ref{E1}), (\ref{E2}), and (\ref{E3}).\par 
  \noindent We now present the following <subequations>:

  \begin{subequations}
    \MarginNum{equation}{A = B + C}{\label{E5a}}
    \MarginNum{equation}{B = C + D}{\label{E5b}}
    \MarginNum{equation}{D = E + F}{\label{E5c}}
  \end{subequations}

  Next we're using `\textbackslash newpage' to demonstrate that equation numbers are in the outside margins, as desired..
\newpage
  Now we reference the above equations (\ref{E5a}), and (\ref{E5c})\footnote{At this point it looks like it's displaying the equations one less level than it's supposed to.}. Next we display the following <equation> with <array>:

  \MarginNum{equation}{
    \begin{array}{|cc|}
      d & e \\
      f & g
    \end{array}       }{\label{E6}}

  \medskip
  \noindent We now Reference the above array as equation (\ref{E6}). \par
  \noindent Here is an example using <align>:
  
  \MarginNum{align}{
    F &= A\times B \\
    G\Cdot D &= H\Cdot P\times Q + B\Cdot V \\
    \vec F &= q(\vec E + v\vec \times \vec B) 
                   }{\label{E7}}

  \noindent Equation number (\ref{E7}) is not placed well, vertically.
  \noindent ``Normal mode'':
  \begin{equation}
    P = Q^2\label{E8}
  \end{equation}
  The reference to equation (\ref{E8}) is working fine.

 % \newpage \layout

\end{document}

相关内容