Formatting List of Tables and List of Algorithms

algorithmstable of contents

I need a special format for the \listoffigures and the \listofalgorithms.

It should be:

List of Tables
      Table 1: T1.....................1

and respective

List of Algorithms
      Algorithm 1: A1.................1

For the Table I found:

\renewcommand*\cfttabpresnum{Table~}
\settowidth{\cfttabnumwidth}{\cfttabpresnum}
\renewcommand{\cfttabaftersnumb}{$\;$$\;$:~}

which works perfectly.

For the Algorithms I found

\let\oldlistofalgorithms\listofalgorithms
\renewcommand{\listofalgorithms}{%
  \begingroup%
  \let\oldnumberline\numberline%
  \renewcommand{\numberline}{Algorithmus:~\oldnumberline}%
  \oldlistofalgorithms%
\endgroup}

from here: Add the word "Algorithm" before each entry in the List of Algorithms
which also works. But the style is

 List of Algorithms
         Algorithm 1 A1................1

so the ":" is missing. I tried to solve it by myself but I couldn't figure out. Could you held me please?

Greets,Tony

Best Answer

The idea is to first register the list of algorithms so that tocloft is aware of it; this can be done, for example using egreg's answer to Customizing the list of listings generated by \lstlistoflistings?. The relevant part, adjusted to the case of algorithms, is

\makeatletter
\begingroup
  \let\newcounter\@gobble
  \let\setcounter\@gobbletwo
  \globaldefs\@ne
  \let\c@loadepth\@ne
  \newlistof{algorithms}{loa}{\listalgorithmname}
\endgroup
\let\l@algorithm\l@algorithms
\makeatother

Once this has been done, you can use the \cft... family of commands to customize the entries format:

\documentclass{book}
\usepackage{tocloft}
\usepackage{algorithm}

\makeatletter
\begingroup
  \let\newcounter\@gobble
  \let\setcounter\@gobbletwo
  \globaldefs\@ne
  \let\c@loadepth\@ne
  \newlistof{algorithms}{loa}{\listalgorithmname}
\endgroup
\let\l@algorithm\l@algorithms
\makeatother

\renewcommand\cfttabaftersnum{:}
\renewcommand\cfttabpresnum{Table~}
\cftsetindents{tab}{1.5em}{5em}

\renewcommand\cftalgorithmsaftersnum{:}
\renewcommand\cftalgorithmspresnum{Algorithm~}
\cftsetindents{algorithms}{1.5em}{7em}

\begin{document}

\listoftables
\cleardoublepage
\listofalgorithms
\cleardoublepage

\begin{table}
\centering A
\caption{test table}
\end{table}

\begin{algorithm}
\centering A
\caption{test algorithm}
\end{algorithm}

\begin{table}
\centering A
\caption{another test table}
\end{table}

\begin{algorithm}
\centering A
\caption{another test algorithm}
\end{algorithm}

\end{document}

An image of the list of tables:

enter image description here

An image of the list of algorithms:

enter image description here