![“Showonlyref” 和 “Subequations” 相互作用解决方法?](https://linux22.com/image/459808/%E2%80%9CShowonlyref%E2%80%9D%20%E5%92%8C%20%E2%80%9CSubequations%E2%80%9D%20%E7%9B%B8%E4%BA%92%E4%BD%9C%E7%94%A8%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95%EF%BC%9F.png)
Daleif 建议的解决方法(见下文)解决了当没有引用一组子方程时编号不正确的问题。但是,如果没有引用特定子方程组中的任何方程,则后续文本的第一行会缩进少量!如何解决这个问题? - 提前感谢您的支持!
在 pachcmd 周围加上花括号可以删除文本中不需要的空格,但是引用不再正确。
\documentclass[a4paper]{article}
\usepackage{mathtools}
%
% Workaround suggested by Daleif:
\mathtoolsset{showonlyrefs=true}
\usepackage{etoolbox}
\patchcmd{\endsubequations}{\setcounter{equation}{\value{parentequation}}}{
\ifnum\value{equation}=0\relax
\addtocounter{parentequation}{-1}
\fi
\setcounter{equation}{\value{parentequation}}%
}{}{}
%
\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 first group of equations:\\
Next line of text ...
\begin{subequations}\label{eq:sub1}
\begin{alignat}{1}
& \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{alignat}
\end{subequations}
%
A second group of equations:\\
Next line of text ...
\begin{subequations}\label{eq:sub2}
\begin{alignat}{1}
& \frac{\text{d}b_1}{\text{d}z} - \beta_1b_1 = C_{12}b_2,\label{eq:3}\\
& \frac{\text{d}b_2}{\text{d}z} - \beta_2b_2 = C_{21}b_1.\label{eq:4}
\end{alignat}
\end{subequations}
%
Last equation:
\begin{equation}\label{G4}
e=a+b+c
\end{equation}
%
For testing purpose: (disable appropriate lines to see what happens) \\
\noindent
the first equation: \eqref{G1}\\
the second equation: \eqref{G2}\\
% the first group of equations: \eqref{eq:sub1} \\
the second group of equations: \eqref{eq:sub2} \\
% specific equations out of the first group: \eqref{eq:1} and/or \eqref{eq:2} \\
specific equation out of the second group: \eqref{eq:3} and/or \eqref{eq:4} \\
the last equation \eqref{G4} \\
%
\textbf{Problem}: If none of the equations of a specific set of subequations is referenced the first line of the subsequent text is indented by a small ammont! (see "A second group of equations" in the above example)
%
\end{document}