2

Setup

In my MWE I am trying to add a "LIST OF ALGORITHMS" into the TOC. Following some examples on here I was able to add a page, however each heading in the TOC became doubled and the name "LIST OF ALGORITHMS" is not capitalised.

MWE

\documentclass[12pt, oneside]{book}

%For Algorithms

%ALGORITHM CODE
\usepackage[linesnumbered,ruled]{algorithm2e}
\usepackage{tocbibind} %for some reason "loa" will only work with this package, however this repeates the titles in the TOC


%TABLE OF CONTENTS CODE
\renewcommand\contentsname{CONTENTS}
\renewcommand\listtablename{LIST OF TABLES}
\renewcommand\listfigurename{LIST OF FIGURES}

%WHAT IM TRYING TO ADD
\newcommand{\listofalgorithmes}{\tocfile{\listalgorithmcfname}{loa}}
%\renewcommand\listofalgorithmes{LIST OF ALGORITHMS}

    \addtocontents{toc}{{\protect\noindent\bfseries Contents\hfill Page No.\bigskip\par}} %contents 
    \addtocontents{lot}{{\protect\noindent\bfseries No.\hfill Title\hfill\hfill Page No.\bigskip\par}} %tables
    \addtocontents{lof}{{\protect\noindent\bfseries No.\hfill Title\hfill\hfill Page No.\bigskip\par}} %figuers
    \addtocontents{loa}{{\protect\noindent\bfseries No.\hfill Title\hfill\hfill Page No.\bigskip\par}} %Alg

     \usepackage[titles]{tocloft}
     \usepackage{xpatch}

    \renewcommand\cftbeforechapskip{0ex}
    \renewcommand\cftchapfont{\mdseries}
    \renewcommand\cftchappagefont{\mdseries}
    \renewcommand\cftchappresnum{Chapter~}
    \renewcommand\cftchapaftersnum{: }
    \newlength\tocindent
    \settowidth\tocindent{\cftchapfont\cftchappresnum9\cftchapaftersnum}
    \edef\cftchapnumwidth{\the\tocindent}
    \edef\cftsecindent{\the\tocindent}
    \advance\tocindent2.3em
    \edef\cftsubsecindent{\the\tocindent}
    \advance\tocindent3.2em
    \edef\cftsubsubsecindent{\the\tocindent}
    \renewcommand\cftsecdotsep{\cftnodots}
    \renewcommand\cftsubsecdotsep{\cftnodots}
    \renewcommand\cftsubsubsecdotsep{\cftnodots}
    \newcommand\tocmainmatter
    {\renewcommand\cftchappagefont{\color{white}}%
    }
    \xapptocmd\mainmatter{\addtocontents{toc}{\protect\tocmainmatter}}{}{}

    % Centring for \chapter* and TOC headers, needed - use back up code below
    \newif\ifschaptertoc
    \makeatletter
    \renewcommand\@makeschapterhead[1]%
     {{\parindent \z@ \centering
     \normalfont
    \interlinepenalty\@M
    \Large \bfseries  #1\par\nobreak
    \vskip 20\p@
    }%
    \@mkboth{\MakeUppercase{#1}}{\MakeUppercase{#1}}%
    \ifschaptertoc
    \addcontentsline{toc}{chapter}{#1}%
    \fi
     }
    \makeatother

    %dots
    \renewcommand{\cftpartleader}{\cftdotfill{\cftdotsep}} %parts
    \renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}} %chapters
    \renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}} %sections
    \renewcommand{\cftsubsecleader}{\cftdotfill{\cftdotsep}} %subsection



%----------------------------BEGIN---------------------------
\begin{document}
\frontmatter

\tableofcontents
\schaptertoctrue


\clearpage
\listofalgorithmes

\clearpage
\listoftables

\clearpage
\listoffigures

%-----------------------------To fill TOC-----------------

\mainmatter

\chapter{Chapter 1}
\section{section 1}

\begin{algorithm}[H]
    \SetKwInOut{Input}{Input}
    \SetKwInOut{Output}{Output}

    \underline{Initialise} conditions\;
    \Input{input of algorithm}
    \Output{output of algorithm}
    \underline{Sequence In Full:} 

      {
       \hspace{5pt}  \textbf{Start}: Start \;
      }
      {
       \hspace{15pt}  Find:  \;
      }
      {
       \hspace{15pt}  Return: \vspace{-20pt}
      }
      {

      \hspace {5pt} \textbf{End}: End
      }

    \caption{Algorithm 1)} \label{alg:1}
\end{algorithm} \bigskip


\end{document}

Question

How do I correct my code above to make "list of algorithms" into "LIST OF ALGORITHMS" and prevent the TOC from repeating "List of Algorithms", "LIST OF TABLES", and "LIST OF FIGURE"?

2 Answers 2

1

Don't use tocbibind, don't use \listofalgorithmes. To change the name of the list redefine \listalgorithmcfname. With those changes (I hope those were all I made) the result should be what you want:

\documentclass[12pt, oneside]{book}

%For Algorithms

%ALGORITHM CODE
\usepackage[linesnumbered,ruled]{algorithm2e}
%\usepackage{tocbibind} %for some reason "loa" will only work with this package, however this repeates the titles in the TOC


%TABLE OF CONTENTS CODE
\renewcommand\contentsname{CONTENTS}
\renewcommand\listtablename{LIST OF TABLES}
\renewcommand\listfigurename{LIST OF FIGURES}
\renewcommand\listalgorithmcfname{LIST OF ALGORITHMS}

%WHAT IM TRYING TO ADD
%\newcommand{\listofalgorithmes}{\tocfile{\listalgorithmcfname}{loa}}
%\renewcommand\listofalgorithmes{LIST OF ALGORITHMS}

    \addtocontents{toc}{{\protect\noindent\bfseries Contents\hfill Page No.\bigskip\par}} %contents 
    \addtocontents{lot}{{\protect\noindent\bfseries No.\hfill Title\hfill\hfill Page No.\bigskip\par}} %tables
    \addtocontents{lof}{{\protect\noindent\bfseries No.\hfill Title\hfill\hfill Page No.\bigskip\par}} %figuers
    \addtocontents{loa}{{\protect\noindent\bfseries No.\hfill Title\hfill\hfill Page No.\bigskip\par}} %Alg

     \usepackage[titles]{tocloft}
     \usepackage{xpatch}

    \renewcommand\cftbeforechapskip{0ex}
    \renewcommand\cftchapfont{\mdseries}
    \renewcommand\cftchappagefont{\mdseries}
    \renewcommand\cftchappresnum{Chapter~}
    \renewcommand\cftchapaftersnum{: }
    \newlength\tocindent
    \settowidth\tocindent{\cftchapfont\cftchappresnum9\cftchapaftersnum}
    \edef\cftchapnumwidth{\the\tocindent}
    \edef\cftsecindent{\the\tocindent}
    \advance\tocindent2.3em
    \edef\cftsubsecindent{\the\tocindent}
    \advance\tocindent3.2em
    \edef\cftsubsubsecindent{\the\tocindent}
    \renewcommand\cftsecdotsep{\cftnodots}
    \renewcommand\cftsubsecdotsep{\cftnodots}
    \renewcommand\cftsubsubsecdotsep{\cftnodots}
    \newcommand\tocmainmatter
    {\renewcommand\cftchappagefont{\color{white}}%
    }
    \xapptocmd\mainmatter{\addtocontents{toc}{\protect\tocmainmatter}}{}{}

    % Centring for \chapter* and TOC headers, needed - use back up code below
    \newif\ifschaptertoc
    \makeatletter
    \renewcommand\@makeschapterhead[1]%
     {{\parindent \z@ \centering
     \normalfont
    \interlinepenalty\@M
    \Large \bfseries  #1\par\nobreak
    \vskip 20\p@
    }%
    \@mkboth{\MakeUppercase{#1}}{\MakeUppercase{#1}}%
    \ifschaptertoc
    \addcontentsline{toc}{chapter}{#1}%
    \fi
     }
    \makeatother

    %dots
    \renewcommand{\cftpartleader}{\cftdotfill{\cftdotsep}} %parts
    \renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}} %chapters
    \renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}} %sections
    \renewcommand{\cftsubsecleader}{\cftdotfill{\cftdotsep}} %subsection



%----------------------------BEGIN---------------------------
\begin{document}
\frontmatter

\tableofcontents
\schaptertoctrue

\clearpage
\listofalgorithms

\clearpage
\listoftables

\clearpage
\listoffigures

%-----------------------------To fill TOC-----------------

\mainmatter

\chapter{Chapter 1}
\section{section 1}

\begin{algorithm}[H]
    \SetKwInOut{Input}{Input}
    \SetKwInOut{Output}{Output}

    \underline{Initialise} conditions\;
    \Input{input of algorithm}
    \Output{output of algorithm}
    \underline{Sequence In Full:} 

      {
       \hspace{5pt}  \textbf{Start}: Start \;
      }
      {
       \hspace{15pt}  Find:  \;
      }
      {
       \hspace{15pt}  Return: \vspace{-20pt}
      }
      {

      \hspace {5pt} \textbf{End}: End
      }

    \caption{Algorithm 1)} \label{alg:1}
\end{algorithm} \bigskip


\end{document}

enter image description here

enter image description here

1

The doubled occurence of LIST OF ALGORITHMS is caused by \tocfile making an entry to the ToC already, and there is a second \addcontentsline in the definition of \@makechapterhead. The \ifschaptertoc test can be shifted to \listofalgorithms, however.

\usepackage[nottoc]{bibind] prevents a doubling of CONTENTS in the ToC, since there is a separate user-defined - contents line in the ToC already, added with \addtocontents.

\documentclass[12pt, oneside]{book}

%For Algorithms

\newif\ifschaptertoc

\usepackage{tocloft}
\usepackage[nottoc]{tocbibind} %for some reason "loa" will only work with this package, however this repeates the titles in the TOC

%TABLE OF CONTENTS CODE

\renewcommand\contentsname{CONTENTS}
\renewcommand\listtablename{LIST OF TABLES}
\renewcommand\listfigurename{LIST OF FIGURES}



%ALGORITHM CODE

\usepackage[linesnumbered,ruled]{algorithm2e}


%WHAT IM TRYING TO ADD

\renewcommand{\listalgorithmcfname}{LIST OF ALGORITHMS}
\newcommand{\listofalgorithmes}{\ifschaptertoc\begingroup\tocfile{\listalgorithmcfname}{loa}\endgroup\fi}


\addtocontents{toc}{{\protect\noindent\bfseries Contents\hfill Page No.\bigskip\par}} %contents 
\addtocontents{lot}{{\protect\noindent\bfseries No.\hfill Title\hfill\hfill Page No.\bigskip\par}} %tables
\addtocontents{lof}{{\protect\noindent\bfseries No.\hfill Title\hfill\hfill Page No.\bigskip\par}} %figuers
\addtocontents{loa}{{\protect\noindent\bfseries No.\hfill Title\hfill\hfill Page No.\bigskip\par}} %Alg

\usepackage{xpatch}

\schaptertoctrue

\renewcommand\cftbeforechapskip{0ex}
\renewcommand\cftchapfont{\mdseries}
\renewcommand\cftchappagefont{\mdseries}
\renewcommand\cftchappresnum{Chapter~}
\renewcommand\cftchapaftersnum{: }
\newlength\tocindent
\settowidth\tocindent{\cftchapfont\cftchappresnum9\cftchapaftersnum}
\edef\cftchapnumwidth{\the\tocindent}
\edef\cftsecindent{\the\tocindent}
\advance\tocindent2.3em
\edef\cftsubsecindent{\the\tocindent}
\advance\tocindent3.2em
\edef\cftsubsubsecindent{\the\tocindent}
\renewcommand\cftsecdotsep{\cftnodots}
\renewcommand\cftsubsecdotsep{\cftnodots}
\renewcommand\cftsubsubsecdotsep{\cftnodots}
\newcommand\tocmainmatter
{\renewcommand\cftchappagefont{\color{white}}%
}
\xapptocmd\mainmatter{\addtocontents{toc}{\protect\tocmainmatter}}{}{}

% Centring for \chapter* and TOC headers, needed - use back up code below
\makeatletter
\renewcommand\@makeschapterhead[1]%
{{\parindent \z@ \centering
    \normalfont
    \interlinepenalty\@M
    \Large \bfseries  #1\par\nobreak
    \vskip 20\p@
  }%
  \@mkboth{\MakeUppercase{#1}}{\MakeUppercase{#1}}%
%  \ifschaptertoc
%  \addcontentsline{toc}{chapter}{#1}%
%  \fi
}
\makeatother

% dots
\renewcommand{\cftpartleader}{\cftdotfill{\cftdotsep}} %parts
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}} %chapters
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}} %sections
\renewcommand{\cftsubsecleader}{\cftdotfill{\cftdotsep}} %subsection



% ----------------------------BEGIN---------------------------
\begin{document}
\frontmatter

\tableofcontents


\clearpage
\listofalgorithmes

\clearpage
\listoftables

\clearpage
\listoffigures

%-----------------------------To fill TOC-----------------

\mainmatter

\chapter{Chapter 1}
\section{section 1}

\begin{algorithm}[H]
    \SetKwInOut{Input}{Input}
    \SetKwInOut{Output}{Output}

    \underline{Initialise} conditions\;
    \Input{input of algorithm}
    \Output{output of algorithm}
    \underline{Sequence In Full:} 

      {
       \hspace{5pt}  \textbf{Start}: Start \;
      }
      {
       \hspace{15pt}  Find:  \;
      }
      {
       \hspace{15pt}  Return: \vspace{-20pt}
      }
      {

      \hspace {5pt} \textbf{End}: End
      }

    \caption{Algorithm 1)} \label{alg:1}
\end{algorithm} \bigskip


\end{document}

enter image description here

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.