引用自定义命令时打印节号

引用自定义命令时打印节号

我有一个自定义命令\goal{}

\newcounter{goalcounter}[section]
\newcommand\goal{\refstepcounter{goalcounter}{\textbf{Goal \thesection.\thegoalcounter}}}

假设在第 1 节中,我有Our first \goal{} is to have fun,其呈现为Our first Goal 1.1 is to have fun。我想稍后在另一节中引用此目标,如下所示

Section 2
Recall that our Goal 1.1 in an earlier section was to have fun.

我该怎么做呢?

换句话说,我如何访问创建目标的章节编号,以便稍后引用它。目前,我只是标记为,\goal{\label{goal11}}然后稍后引用为... our Goal 1.\cref{goal11} in ...。有没有更好的方法?

多谢。

答案1

使用 时,会存储\label最新的步进计数器(通过)。具体来说,对于计数器。因此,您需要将部分编号定义为目标编号的一部分,如下所示:\refstepcounter\the<cntr><cntr>

\renewcommand{\thegoalcounter}{\thesection.\arabic{goalcounter}}

相关内容