子方程与 showonlyrefs 结合不起作用

子方程与 showonlyrefs 结合不起作用

subequations结合showonlyrefs不起作用。有解决方法吗?

\documentclass[a4paper]{article}
\usepackage{mathtools}
\mathtoolsset{showonlyrefs=true}
\begin{document}
\noindent First equation:
\begin{equation}\label{G1}
  c=a+b
\end{equation}
Second equation:
\begin{equation}\label{G2}
  d=a-b
\end{equation}
A group of equations:
\begin{subequations}\label{eq:sub}
  %\noeqref{eq:1,eq:2}
  \begin{gather}
    \frac{\text{d}b_1}{\text{d}z} - \beta_1b_1 = C_{12}b_2,\label{eq:1}\\
    \frac{\text{d}b_2}{\text{d}z} - \beta_2b_2 = C_{21}b_1.\label{eq:2}
  \end{gather}
\end{subequations}
Last equation:
\begin{equation}\label{G4}
  e=a+b+c
\end{equation}
the following equations will be referenced in the doucment:\\
the first equation: \eqref{G1}\\
%the first equation: \eqref{G2}\\
%the group of equations: \eqref{eq:sub} \\
%specific equations out of the group: \eqref{eq:1} und \eqref{eq:2} \\
the last equation \eqref{G4} \qquad ERROR: the label sould be (2) !!!\\
\\
Unfortunately I cannot figure out what's wrong. In the actual configuration I wanted to have the last equation the label (2) sice only the first and last equations are referenced!
\end{document} 

提前感谢您的支持!

答案1

环境subequations根本不适合其内容不被编号。

如果没有,就会遇到类似的问题mathtools

\documentclass[a4paper]{article}
\usepackage{amsmath}
\begin{document}

\begin{equation} \label{A}  A \end{equation}
\begin{subequations}
  \begin{equation*} \label{B}  B \end{equation*}
 \end{subequations}
\begin{equation} \label{C}  C \end{equation}

\end{document}

在此处输入图片描述

这是一个解决方法:

\usepackage{etoolbox}
\patchcmd{\endsubequations}{\setcounter{equation}{\value{parentequation}}}{
  \ifnum\value{equation}=0\relax
    \addtocounter{parentequation}{-1}
  \fi
  \setcounter{equation}{\value{parentequation}}%
}{}{}

(编辑:更短的补丁并记住成功/失败的参数)

不确定它是否涵盖了所有内容。这个想法是,如果计数器equation在环境结束时仍为零,那么除了将equation值重置为之前的值之外,subequations我们还会将添加的值添加-1到计数器中。+1subequations

请注意,如果与 结合,当前解决方案会给出重复目的地警告hyperref

相关内容