5

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

3

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

  • Probably the indentation can be adjusted to be the same in both lists... – karlkoeller Sep 4 '13 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. – Gonzalo Medina Sep 4 '13 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. – karlkoeller Sep 4 '13 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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.