3

I have been fighting with tocloft to get it to apply some customizations across all the listings, but it seems that they only work for the default ones like "tocs", "lofs" and "lots". For the ones defined by me or the ones like algorithms with its own "loa" it does not work:

\documentclass{book}
    \usepackage{tocloft}
    \usepackage{algorithm2e}
    \usepackage{lmodern}
    \usepackage[T1]{fontenc}
    \usepackage{xcolor}
    \definecolor{red}{RGB}{180,40,50}

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

    \renewcommand\cftdotsep{0}
    \renewcommand\cftdot{\color{red}\_}

    \renewcommand\cftalgorithmtdotsep{0}
    \renewcommand\cftalgorithmtleader{\color{red}\_}


    \begin{document}

        \tableofcontents
        \listofalgorithms
        \addcontentsline{toc}{chapter}{List of Algorithms}
        \listoftables
        \addcontentsline{toc}{chapter}{List of Tables}

        \chapter{chapter one}
            \section{section one}
                \begin{table}
                \centering A
                \caption{test table}
                \end{table}

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

        \chapter{chapter two}
            \section{section one}
                \begin{table}
                \centering A
                \caption{another test table}
                \end{table}

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

    \end{document}

enter image description here

2

If you look at the .loa file you'll see

\addvspace {10\p@ }
\addvspace {10\p@ }
\contentsline {algocf}{\numberline {1}{\ignorespaces test algorithm}}{5}
\addvspace {10\p@ }
\contentsline {algocf}{\numberline {2}{\ignorespaces another test algorithm}}{7}

so, rather than \let\l@algorithm\l@algorithms you have to say

\let\l@algocf\l@algorithmt

Some other adjustments must be made. Here's the complete example.

\documentclass{book}
\usepackage{tocloft}
\usepackage{algorithm2e}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\definecolor{red}{RGB}{180,40,50}

\makeatletter
\begingroup
  \let\newcounter\@gobble
  \let\setcounter\@gobbletwo
  \globaldefs\@ne
  \let\c@loadepth\@ne
  \newlistof{algorithmt}{loa}{\listalgorithmcfname}
\endgroup
\let\l@algocf\l@algorithmt
\makeatother

\renewcommand\cftdotsep{0}
\renewcommand\cftdot{\color{red}\_}

\renewcommand\cftalgorithmtdotsep{0}
\let\cftalgorithmtleader\cftsecleader


\begin{document}

\tableofcontents
\listofalgorithms
\addcontentsline{toc}{chapter}{List of Algorithms}
\listoftables
\addcontentsline{toc}{chapter}{List of Tables}

\chapter{chapter one}
\section{section one}
\begin{table}
\centering A
\caption{test table}
\end{table}

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

\chapter{chapter two}
\section{section one}
\begin{table}
\centering A
\caption{another test table}
\end{table}

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

\end{document}

enter image description here

You probably want to set also the indentation to a proper value.

  • Thanks a lot! For the indentation I just added \let\cftalgorithmtindent\cftsecindent and everything looks like I wanted. – luke_16 Nov 27 '13 at 11:51

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.