“Showonlyref” 和 “Subequations” 相互作用解决方法?

“Showonlyref” 和 “Subequations” 相互作用解决方法?

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}

答案1

尝试

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

消除虚假空格。

b

相关内容