How to define a new counter in LaTeX that also includes a section number?

Given that I have defined a new environment for which the counter is supported:

\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 this 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}

Text with an inscription and a number is displayed here. Since it uses \ thechapter, this number will also contain the section number; that is, the first environment in chapter 3 will be numbered in 3-1. At the exit, that is.

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

+5
source share
1 answer

Insert:

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

and get

\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}
}
+8

All Articles