[Tex/LaTex] Typesetting listofalgorithms like listoffigures and listoftables using titletoc

algorithmstable of contentstitletoc

I would like to typeset the \listofalgorithms generated by package algorithm in the same way than the \listoffigures and \listoftables, using package titletoc. However, I have not been able to find a solution to that problem.

Here is a MWE:

\documentclass[12pt,a4paper]{book}

\usepackage{titletoc}
\usepackage[chapter]{algorithm}
\usepackage{algpseudocode}

\renewcommand{\cleardoublepage}{\clearpage}

\titlecontents{figure}[2.0em]{}{\contentslabel{2.3em}}{}{\titlerule*[0.25pc]{.}\contentspage}{}
\titlecontents{table}[2.0em]{}{\contentslabel{2.3em}}{}{\titlerule*[0.25pc]{.}\contentspage}{}
\contentsuse{algorithm}{loa}
\titlecontents{algorithm}[2.0em]{}{\contentslabel{2.3em}}{}{\titlerule*[0.25pc]{.}\contentspage}{}

\begin{document}

\listoffigures
\listoftables
\listofalgorithms

\chapter{Nice chapter}

\begin{figure}[t]
    \caption{Nice figure}
\end{figure}

\begin{table}[t]
    \caption{Nice table}
\end{table}

\begin{algorithm}[t]
    \caption{Nice algorithm}
\end{algorithm}

\end{document}

Can someone think of a way to do it ?

Best Answer

The \listofalgorithms command is defined by the float package. One can do by copying the definition of \listoftables and patching it:

\documentclass[12pt,a4paper]{book}

\usepackage{titletoc}
\usepackage[chapter]{algorithm}
\usepackage{algpseudocode}
\usepackage{etoolbox}

\titlecontents{figure}[2.0em]{}{\contentslabel{2.3em}}{}{\titlerule*[0.25pc]{.}\contentspage}{}
\titlecontents{table}[2.0em]{}{\contentslabel{2.3em}}{}{\titlerule*[0.25pc]{.}\contentspage}{}
\contentsuse{algorithm}{loa}
\titlecontents{algorithm}[2.0em]{}{\contentslabel{2.3em}}{}{\titlerule*[0.25pc]{.}\contentspage}{}

\let\listofalgorithms\listoftables
\patchcmd{\listofalgorithms}{\listtablename}{\listalgorithmname}{}{}
\patchcmd{\listofalgorithms}{\listtablename}{\listalgorithmname}{}{}
\patchcmd{\listofalgorithms}{\listtablename}{\listalgorithmname}{}{}
\patchcmd{\listofalgorithms}{lot}{loa}{}{}

\begin{document}
...
\end{document}

enter image description here