我如何将标签推送到我的自定义环境方程中以实现正确对齐?

我如何将标签推送到我的自定义环境方程中以实现正确对齐?

包含方程式的自定义环境的标签没有将标签放在正确的位置。我可能没有正确的搜索词,因为我找不到此问题的解决方案。这是我的 MWE:

\documentclass{article}

\usepackage{mathtools}

% PRB: Tag placement on a line does not position flush right.
\newcounter{derivativeFormula}
\renewcommand*{\thederivativeFormula}{\textsc{df}\arabic{derivativeFormula}}
\usepackage{zref-savepos}
\makeatletter
\newenvironment{DerivativeFormula}{                               %
    \def\equation{$$\refstepcounter{derivativeFormula}}           % order
    \def\@eqnnum{{\normalfont \normalcolor \thederivativeFormula}}% is
    \equation                                                     % important!
}{                                                                %
    \@gobble                                                      %
    \print@eqnum{(\thederivativeFormula)}                         %
    \endequation                                                  %
}
\makeatother

\begin{document}

A regular equation which should be reference (1).
\begin{equation}\label{eqn:testA}
  \frac{dx}{dx} = 1
\end{equation}

A regular equation which should be reference (2).
\begin{equation}\label{eqn:testB}
  \frac{d(u+v)}{dx} = \frac{du}{dx}+\frac{dv}{dx}
\end{equation}

This is the \texttt{DerivativeFormula} environment. I want the tag 
to be flush right. It should read (DF1) but way that way -->.
\begin{DerivativeFormula}\label{eqn:testC}
  \frac{d(uv)}{dx} = u\frac{du}{dx} + v\frac{du}{dx}
\end{DerivativeFormula}

Another plain equation to check numbering and reference (3).
\begin{equation}\label{eqn:testD}
  \frac{du^n}{dx} = nu^{n-1}\frac{du}{dx}
\end{equation}

The values of the references are, in order, 
\eqref{eqn:testA}, \eqref{eqn:testB}, \eqref{eqn:testC}, \eqref{eqn:testD}.

\end{document}

在此处输入图片描述

答案1

关键是使用\tag,芭芭拉提醒我,当(或)加载时\tag,在里面工作,因此我进行了编辑,以用环境替换我的选择。equationamsmathmathtoolsgatherequation

\documentclass{article}

\usepackage{mathtools}

\newcounter{derivativeFormula}
\renewcommand*{\thederivativeFormula}{\textsc{df}\arabic{derivativeFormula}}
\usepackage{zref-savepos}
\makeatletter
\newenvironment{DerivativeFormula}{
    \refstepcounter{derivativeFormula}
    \equation
}{
    \tag{\thederivativeFormula}
    \endequation
}
\makeatother
\begin{document}
A regular equation which should be reference (1).
\begin{equation}\label{eqn:testA}
  \frac{dx}{dx} = 1
\end{equation}

A regular equation which should be reference (2).
\begin{equation}\label{eqn:testB}
  \frac{d(u+v)}{dx} = \frac{du}{dx}+\frac{dv}{dx}
\end{equation}

This is the \texttt{DerivativeFormula} environment. I want the tag 
to be flush right. It should read (DF1) but way that way $\rightarrow$.
\begin{DerivativeFormula}\label{eqn:testC}
  \frac{d(uv)}{dx} = u\frac{dv}{dx} + v\frac{du}{dx}
\end{DerivativeFormula}

Another plain equation to check numbering and reference (3).
\begin{equation}\label{eqn:testD}
  \frac{du^n}{dx} = nu^{n-1}\frac{du}{dx}
\end{equation}

The values of the references are, in order, 
\eqref{eqn:testA}, \eqref{eqn:testB}, \eqref{eqn:testC}, \eqref{eqn:testD}.
Here is the next derivative formula:
\begin{DerivativeFormula}\label{eqn:testZ}
  \frac{d(uw)}{dx} = u\frac{dw}{dx} + w\frac{du}{dx}
\end{DerivativeFormula}
\end{document}

在此处输入图片描述

附言:我还纠正了中的数学运算(DF1)

相关内容