Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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}

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?

like image 578
Egon Willighagen Avatar asked Dec 14 '09 20:12

Egon Willighagen


1 Answers

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}
}
like image 52
Alexey Malistov Avatar answered Nov 03 '22 07:11

Alexey Malistov