I want the algorithm to be prefix with chapter
say in chapter 1, it should be 1.1, 1.2, for chapter 2, it should be 2.1, 2.2
But for my case, i only have 1,2,3,… across all chapters, how should I change it?
The include package is listed as followed:
\usepackage[ruled,vlined,linesnumbered,algo2e,resetcount,algochapter]{algorithm2e}
Here is the minimal working example
\documentclass[11pt]{book}
\usepackage{bigstrut}
\usepackage{stmaryrd}
\usepackage{tipa}
\usepackage{amssymb}
\usepackage{textcomp}
\usepackage{times}
\usepackage{pifont}
\usepackage{amsfonts}
\usepackage{makeidx}
\usepackage{moreverb}
\usepackage{calc}
\usepackage{dsfont}
\usepackage{tikz}
\usepackage{color}
\usepackage{etex}
\usepackage{ctable}
\usepackage{bigstrut}
\usepackage{pifont}
\usepackage{amsfonts}
\usepackage{makeidx}
\usepackage{moreverb}
\usepackage{scalefnt}
\usetikzlibrary{shapes.geometric, positioning, fit, calc}
\usetikzlibrary{decorations.markings}
\usepackage{scalefnt}
\usepackage{pgf}
\usepackage{graphicx}
\usepackage{pgfplots}
\usepackage{verbatim}
\usetikzlibrary{
shapes.geometric,
positioning,
fit,
calc
}
\usepackage{amsmath}
\usetikzlibrary{arrows,automata,positioning,shapes,patterns}
\usepackage{etex}
\usepackage{amsmath, url, proof} % mathabx,
\usepackage{textcomp}
\usepackage{listings}
\usepackage{float}
\usepackage{multirow}
\usepackage[ruled,vlined,linesnumbered,algo2e,resetcount,algochapter]{algorithm2e}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}
\usepackage{wrapfig}
\usepackage{graphicx}
\usepackage[latin1]{inputenc}
\usetikzlibrary{trees}
\usepackage{verbatim}
\usetikzlibrary{trees,decorations.pathmorphing}
\usepackage{listings}
\usepackage[T1]{fontenc}
\usepackage[scaled]{beramono}
\usepackage{lipsum}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\pgfsysdriver{pgfsys-dvipdfm.def}
\usepackage{pgfplots}
\pgfplotsset{compat=1.3}
\usepackage{epsfig}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,positioning}
\usepackage{epsf}
\usepackage{amsmath,amssymb,amsfonts} %
\usepackage{graphicx}
\usepackage{ltlfonts}
\usepackage{textcomp}
\usepackage{color}
\usepackage{chngcntr}
\usepackage{latexsym} % latex symbols
\usepackage{amsthm} % for defining theorems
\usepackage{syntonly} % verify syntax, not very important
\usepackage{lscape}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{caption}
\usepackage{subcaption}% http://ctan.org/pkg/subcaption
\captionsetup{compatibility=false}
\DeclareCaptionSubType*{algorithm}
\renewcommand\thesubalgorithm{\thetable\alph{subalgorithm}}
\DeclareCaptionLabelFormat{alglabel}{Alg.~#2}
\usepackage{pxfonts, pifont} % About fonts
\usepackage{setspace}
\usepackage{graphics}
\usepackage{multirow} % To write complicated tables
\usepackage{colortbl} % Colors
\usepackage{rotating} % For rotating tables
\usepackage{verbatim} % Comment Environment
% eg. \begin{comment}
% \end{comment}
\usepackage{mdwlist}
%%
\usepackage[titletoc]{appendix}
\usepackage{url}
\usepackage{style/mythesis}
\usepackage{lscape}
\usepackage{listings}
\newcommand{\myfontsize}{\fontsize{9}{10}\selectfont}
\usepackage[backref=section,colorlinks=true,hyperfootnotes=false]{hyperref}
\hypersetup{
colorlinks,%
citecolor=black,%
filecolor=black,%
linkcolor=black,%
urlcolor=black,breaklinks = true, %
pdfprintscaling = None, %
unicode = true, %
bookmarksnumbered = true,
}
\setcounter{secnumdepth}{3}
\interfootnotelinepenalty=10000
\begin{document}
\newpage
\pagenumbering{roman}
\singlespacing{ \listofalgorithms
\addcontentsline{toc}{section}{\numberline{}\hspace{-.35in}{\bf List
of Algorithms}}}
\doublespacing
\chapter{chapter1}~\label{a1}
\begin{algorithm}[H]
\centering
a
\caption{algo}\label{algo1}
\end{algorithm}
\chapter{chapter2}~\label{a2}
\begin{algorithm}[H]
\centering
a
\caption{algo}\label{algo2}
\end{algorithm}
\begin{algorithm}[H]
\centering
a
\caption{algo}\label{algo3}
\end{algorithm}
\end{document}
Best Answer
Since you are using both the
algorithm2e
andalgorithm
packages, and both of them implement some same commands/environments, you had to use thealgo2e
option foralgorithm2e
to prevent a clash and this overrides the settings for the counter that you set as options foralgorith2e
, since the environment that will be used is the one fromalgorithm
. You have three possible solutions:If you don't need the
algorithm
package, load onlyalgorithm2e
and notalgorithm
and load the former without thealgo2e
option:If you really need both
algorithm2e
andalgorithm
in your document, and you want to use thealgorithm
environment (from thealgorithm
package) add the following lines to your preamble, after loading the packages:A complete example:
If you really need both
algorithm2e
andalgorithm
in your document, and you want to use thealgorithm
environment (from thealgorithm2e
package), use thealgorithm2e
environment (thealgo2e
option renamesalgorithm
toalgorithm2e
):By the way (not related to the question), you are loading packages more than once; this should be avoided.