1

I am working on the thesis and have four algorithms, two in Chapter 3 and two in Chapter four. The algorithms appear 3.1, 3.2, 4.3 and 4.4. When I remove Chapter 3 from the thesis, the 4.3 and 4.4 become 3.1 and 3.2 respectively. How to make it 3.1, 3.2 and 4.1, 4.2?

I do not know how I can submit the MWE for this question.

Dr. Abrar
  • 329

1 Answers1

0

You probably have the following setup:

\documentclass{report}

\usepackage{algorithm} \renewcommand{\thealgorithm}{\thechapter.\arabic{algorithm}}

\begin{document}

\setcounter{chapter}{2}% Just for this example \chapter{Third chapter}

\begin{algorithm} \caption{First algorithm}% 3.1 \end{algorithm}

\begin{algorithm} \caption{Second algorithm}% 3.2 \end{algorithm}

\chapter{Fourth chapter}

\begin{algorithm} \caption{Third algorithm}% 4.3 \end{algorithm}

\begin{algorithm} \caption{Fourth algorithm}% 4.4 \end{algorithm}

\end{document}

The above reproduces your problem - only adding the chapter counter representation to your setup without making it reset with every new \chapter. This is the default behaviour of algorithm - providing continuous numbering of algorithms throughout the document, since there's not that many algorithms in any document in general.

To change this, you can either use chngcnt or amsmath together with

\usepackage{chngcntr}% also works with \usepackage{amsmath}
\counterwithin{algorithm}{chapter}

and remove the \renewcommand{\thealgorithm}. For more information, see Continuous v. per-chapter/section numbering of figures, tables, and other document elements.

Werner
  • 603,163