# How to define in LaTeX a new counter that includes the chapter number too?

Tag: latex Author: caoweiy Date: 2009-11-28
 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}  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. 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?

Insert:

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


and get

\newcounter{bioclipse}
\def\thebioclipse{\thechapter-\arabic{bioclipse}}
\newenvironment{bioclipse}[2][]{