3

I'm currently trying to create a template of my own to unifiy all the documents (article class) I write for school and I'd like to change the functioning of the counters for the equations, figures and tables.

In fact, I would like for the counters to work as :

Figure S.SS.XX with S the section number, SS the subsection number and XX being a counter reset at the end of each sub section.

Do you know how to do that ?

Thanks ahead !

2

This is pretty simple with chngcntr package and \counterwithin

This command places the relevant counter from the first argument in the reset list of the counter in the 2nd argument.

The counter output will automatically adapted with this command.

Be careful with hyperref though: The package must be loaded before \counterwithin to provide correct linking!

\documentclass{article}


\usepackage{chngcntr}

%\usepackage{hyperref}% Must be done before \counterwithin!

\counterwithin{figure}{subsection}
\counterwithin{equation}{subsection}
\counterwithin{table}{subsection}


\begin{document}

\section{Foo}

\subsection{Foo}
\begin{equation}
  E = mc^2
\end{equation}

\begin{figure}
  \caption{A foo figure}
\end{figure}


\begin{figure}
  \caption{Another foo figure}
\end{figure}


\section{Foobar}


\subsection{Foo}
\begin{equation}
  E = mc^2
\end{equation}


\begin{figure}
  \caption{A foo figure}
\end{figure}


\begin{figure}
  \caption{Another foo figure}
\end{figure}


\end{document}
2

You can redefine the the \theequation -command like this:

\renewcommand{\theequation}{\thesubsection.\arabic{equation}}

This should create equation labels as you wish. Analog to that for figures and tables:

 \renewcommand{\thefigure}{\thesubsection.\arabic{figure}}
 \renewcommand{\thetable}{\thesubsection.\arabic{table}}

The counters for equation, figure and table can be automatically reset by using these commands:

\usepackage{chngcntr}
\counterwithin*{equation}{subsection}
\counterwithin*{figure}{subsection}
\counterwithin*{table}{subsection}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.