我是这个 stackexchange 小组的新手,所以如果我的问题不恰当,请原谅我。如果需要一些额外的信息,请发表评论,我会附上这些详细信息。
我正在使用以下几行
\begin{subequations}
\renewcommand{\theequation}{\arabic{section}.\theparentequation.\arabic{equation}}
\begin{align}
& y = (c-r_x)*x + r_x*gbest, \label{eq:0.1} \\
& y = (c-r_n)*x - r_n*gbest, \label{eq:0.2} \\
\end{align}
\label{eq:eqn}
\end{subequations}
但调用\cref{eq:eqn}
会打印 eq.(1) 而不是 eq(.1)。当我引用子方程时不会发生这种情况。有人可以指导我如何实现这一点吗?
答案1
您应该\numberwithin{equation}{section}
在序言中使用,而不是放在\thesection
里面\theequation
。
\documentclass{article}
\usepackage{amsmath}
\usepackage{cleveref}
\numberwithin{equation}{section}
\begin{document}
\section{TEST}
Intro
\begin{subequations}
\renewcommand{\theequation}{\theparentequation.\arabic{equation}}
\begin{align}
& y = (c-r_x)*x + r_x*gbest, \label{eq:0.1} \\
& y = (c-r_n)*x - r_n*gbest, \label{eq:0.2}
\end{align}
\label{eq:eqn}
\end{subequations}
And then refer to equation \ref{eq:0.2}, which is within \cref{eq:eqn}.
\end{document}
答案2
像这样吗?
\documentclass{article}
\usepackage{amsmath,cleveref}
\numberwithin{equation}{section}
\begin{document}
\setcounter{section}{3} % just for this example
\begin{subequations}
\renewcommand{\theequation}{\theparentequation.\arabic{equation}}
\begin{align}
y_x &= (c-r_x)x + r_x g_{\mathrm{best}}, \label{eq:0.1} \\
y_n &= (c-r_n)x - r_n g_{\mathrm{best}} \label{eq:0.2}
\end{align}
\label{eq:eqn}
\end{subequations}
\verb|\cref{eq:eqn} and \cref{eq:0.1}| produces
``\cref{eq:eqn} and \cref{eq:0.1}''.
\end{document}