6

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

4
  • What do you use to produce your algorithms?
    – Werner
    Commented Sep 4, 2013 at 17:12
  • See this answer of mine: tex.stackexchange.com/a/126850/27635. That one does the same thing for listings. Try to adapt it for algorithms. Commented Sep 4, 2013 at 17:20
  • Can you provide a minimal working example (MWE) so we know which is the best way to go? Commented Sep 4, 2013 at 18:54
  • @Werner: I use lstlistings to write my pseudocode.
    – Tony
    Commented Sep 4, 2013 at 19:02

2 Answers 2

4

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

3
  • Probably the indentation can be adjusted to be the same in both lists... Commented Sep 4, 2013 at 18:59
  • @karlkoeller the indentation of entries in both lists is the same (the second image is a little shifted to the right): entries in both lists begin at a distance of 1.5em from the left margin. Commented Sep 4, 2013 at 19:02
  • I mean the spacing after the number. That is I would use something like \setlength{\cftalgorithmsindent}{1.5em} \settowidth{\cftalgorithmsnumwidth}{\cftalgorithmspresnum} \addtolength{\cftalgorithmsnumwidth}{2.3em} instead of \cftsetindents{algorithms}{1.5em}{7em}. The same for the LOT. Commented Sep 4, 2013 at 19:13
0

If someone is looking for the same above for "lstlistings" this should do it:

\makeatletter
\begingroup\let\newcounter\@gobble\let\setcounter\@gobbletwo
  \globaldefs\@ne \let\c@loldepth\@ne
  \newlistof{listings}{lol}{\lstlistlistingname}
\endgroup
\let\l@lstlisting\l@listings
\AtBeginDocument{\addtocontents{lol}{\protect\addvspace{10\p@}}}
\makeatother
\renewcommand{\lstlistoflistings}{\listoflistings}

\renewcommand\cftlistingsaftersnum{:}
\renewcommand\cftlistingspresnum{Listing~}
\cftsetindents{listings}{1.5em}{7em}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .