GeneralRe-setting a custom made counter for each new chapter

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Eenzc
Posts: 48
Joined: Thu Jun 26, 2008 2:38 pm

Re-setting a custom made counter for each new chapter

Post by Eenzc »

Hello again,

A while ago StefanK help me to create a series of new tags and enviroments so that I could autogenerate a Listof... page for chemical equations which were numbered in my document separate from mathematical equations.

This was greatly sucessful and has worked on many reports I have written.

Now I'm writting my thesis and have started a series of chapers. I've noticed that the counter keeps incrementing even though I have changed chapter.

So my chemical equation in chapter one are numbered [1.1], second [1.2].
However at the start of chapter two they are numbered [2.3] and not [2.1] as I'd like.

Any ideas?

The code is :

Code: Select all

% Special Symbols Defined for Main Preamble

%%%%% to create a chemicalequation float

\usepackage{float}
\newfloat{chemicalequation}{htbp}{cex}[chapter]
\floatname{chemicalequation}{}

%%%%% create chemequation environment

\newcounter{chemequation}
\renewcommand*\thechemequation{[\thechapter.\arabic{chemequation}]}
\newenvironment{chemequation}{%
\stepcounter{chemequation}%
\begin{equation}}%
{\tag*{\thechemequation}%
\end{equation}}

%%%%% create chemtag to iterate and ref chemequations in an align environment

\newcommand*\chemtag{%
\stepcounter{chemequation}%
\tag*{\thechemequation}}

%%%%%

\newcommand\chemicalcaption[1]{%
  \refstepcounter{chemicalequation}
  \addcontentsline{cex}{section}%
    {\protect\numberline{\thechemicalequation}{\ignorespaces #1}}
}

%%%%%

It is frequently used in the mainmatter as:

Using the following packages:

Code: Select all

%%%% Math Packages 
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}

%%%% Chemistry Specific
\usepackage{sistyle} % includes SI style sheets
\usepackage[version=3]{mhchem}

Code: Select all


\begin{chemicalequation} [H]
\begin{align}
\ce{O2 + H2O + 2e}				~& \ce{<=> HO2^{-} + OH^{-}}
~& E\stst : \SI{-0.076}{V} \chemtag \\
\ce{O2 + 2H2O + 2e}			~& \ce{<=> H2O2 + 2OH^{-}}
~& E\stst : \SI{-0.146}{V} \chemtag \\
\ce{O2 + 2H2O + 4e}			~& \ce{<=> 4OH^{-}}
~& E\stst : \SI{+0.401}{V} \chemtag \\
\ce{HO2^{-} + H2O + 2e}	~& \ce{<=> 3OH-}
~& E\stst : \SI{+0.878}{V} \chemtag
\end{align}
\chemicalcaption{Chemical_Equations_O}
\label{chem:Chemical_Equations_O}
\end{chemicalequation}

Any help gratefully recieved.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Re-setting a custom made counter for each new chapter

Post by gmedina »

Hi,

you could use the \counterwithin command provided by the chngcntr package.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re-setting a custom made counter for each new chapter

Post by localghost »

A simple option will do the trick.

Code: Select all

\newcounter{chemequation}[chapter]
Additionally you should think about replacing siunits by the siunitx package.


Best regards
Thorsten¹
Eenzc
Posts: 48
Joined: Thu Jun 26, 2008 2:38 pm

Re: Re-setting a custom made counter for each new chapter

Post by Eenzc »

Brilliant the [chapter] option works perfectly.

Thanks again.
Post Reply