如何在LaTeX中定义一个也包含章号的新计数器? [英] How to define in LaTeX a new counter that includes the chapter number too?

查看:368
本文介绍了如何在LaTeX中定义一个也包含章号的新计数器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于我已经定义了一个维护计数器的新环境:

Given I have defined a new environment for which a counter is maintained:

\newcounter{bioclipse}
\newenvironment{bioclipse}[2][]{
   \begin{shaded}\refstepcounter{bioclipse}\par\medskip\noindent%
   \textbf{Bioclipse Excursion~\thechapter-\thebioclipse #1: #2
   \vspace{0.1cm} \hrule \vspace{0.1cm}}
   \rmfamily}{\medskip \end{shaded}
}

现在,我可以在这样的环境中添加标签:

Now, I can add a label to such an environment:

\begin{bioclipse}{Wizards: New Molecule from SMILES}
  \label{chapCompRepr:ex:fromSMILESWizard}
  Bioclipse has a \textit{New Wizard} to create a new chemical graph.
\end{bioclipse}

这将输出带有标题和数字的文本.因为它使用\ thechapter,所以该数字也将包括章号;也就是说,第3章中的第一个环境将以3-1编号.在输出中就是这样.

This outputs a text with caption and a number. Because it uses \thechapter, this number will include the chapter number too; that is, the first environment in Chapter 3, will be numbered in 3-1. In the output, that is.

但是,当我使用\ ref {chapCompRepr:ex:fromSMILESWizard}进行引用时,该数字不包括章节号...我应该如何更改环境定义或包含该章节号的计数器定义,并重置每个章节的第二个数字?

However, when I refer to it with \ref{chapCompRepr:ex:fromSMILESWizard}, this number does not include the chapter number... How should I change my environment definition, or counter definition that it includes the chapter number, and resets the second number for each chapter?

推荐答案

插入:

\def\thebioclipse{\thechapter-\arabic{bioclipse}}

并获得

\newcounter{bioclipse}
\def\thebioclipse{\thechapter-\arabic{bioclipse}}
\newenvironment{bioclipse}[2][]{
   \begin{shaded}\refstepcounter{bioclipse}\par\medskip\noindent%
   \textbf{Bioclipse Excursion~\thebioclipse #1: #2
   \vspace{0.1cm} \hrule \vspace{0.1cm}}
   \rmfamily}{\medskip \end{shaded}
}

这篇关于如何在LaTeX中定义一个也包含章号的新计数器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆