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
到计数器中。+1
subequations
请注意,如果与 结合,当前解决方案会给出重复目的地警告hyperref
。