4

How can I adjust the left margin of the list of algorithms?

What I have tried

For the list of figures and tables, the left margin could be adjusted like explained in Adjusting left margin of LOT and LOF :

\renewcommand\l@figure{\@dottedtocline{1}{0em}{2.3em}}
\renewcommand\l@table{\@dottedtocline{1}{0em}{2.3em}}

However, this does not work:

\renewcommand\l@algorithm{\@dottedtocline{1}{0em}{2.3em}}

The margin is not affected and I get the following warning:

Command \l@algorithm undefined. \renewcommand\l@algorithm

I have tried several variations: l@algorithms, l@algo, but none works. I was able to find the definition of l@figure in book.cls, but I could not find anything related to list of algorithms.

MWE

\documentclass{scrbook}

\makeatletter \renewcommand\l@figure{@dottedtocline{1}{0em}{2.3em}} \makeatother

\usepackage{algorithm}

\begin{document}

\begin{algorithm} \caption{An algorithm} \end{algorithm}

\begin{figure} \caption{A figure} \end{figure}

\listoffigures \listofalgorithms

\end{document}

Output:

enter image description here enter image description here

Martin
  • 114

2 Answers2

5

The KOMA-Script classes load and use package tocbasic. Therefore you do not have to redefine internal commands.

The indent of figure and table entries can be changed by

\DeclareTOCStyleEntries[indent=0pt]{tocline}{figure,table}

If you want to clone the figure settings for the algorithm entries, you can use:

%get list of algorithms under control of tocbasic:
\addtotoclist[float]{loa}
\renewcommand{\listofalgorithms}{\listoftoc[\listalgorithmname]{loa}}
% algorithm entries should use same settings as figure entries
\DeclareTOCStyleEntry[
  level:=figure,
  indent:=figure,
  numwidth:=figure
]{tocline}{algorithm}

Example:

\documentclass{scrbook}
\usepackage{algorithm}
% adjust the indent of figure and table entries
\DeclareTOCStyleEntries[indent=0pt]{tocline}{figure,table}

%get list of algorithms under control of tocbasic: \addtotoclist[float]{loa} \renewcommand{\listofalgorithms}{\listoftoc[\listalgorithmname]{loa}} % algorithm entries should use same settings as figure entries \DeclareTOCStyleEntry[ level:=figure, indent:=figure, numwidth:=figure ]{tocline}{algorithm}

\begin{document}

\begin{algorithm}\caption{An algorithm}\end{algorithm} \begin{figure}\caption{A figure}\end{figure} \begin{table}\caption{A table}\end{table}

\listoffigures \listoftables \listofalgorithms \end{document}

esdd
  • 85,675
4

From how the \listofalgorithms and \listof are defined,

$ latexdef -p algorithm -s listofalgorithms
% algorithm.sty, line 97:
\newcommand{\listofalgorithms}{\listof{algorithm}{\listalgorithmname}}

$ latexdef -p float -s \listof % float.sty, line 127: \newcommand*{\listof}[2]{% @ifundefined{ext@#1}{\float@error{#1}}{% @namedef{l@#1}{@dottedtocline{1}{1.5em}{2.3em}}% \float@listhead{#2}% \begingroup\setlength{\parskip}{\z@}% @starttoc{@nameuse{ext@#1}}% \endgroup}}

we can see \l@algorithm is not defined until \listof{algorithm}{...} is used. This explains the error Command \l@algorithm undefined., and will also overwrite existing definition of \l@algorithm.

In example below the problem is solved by redefining \l@algorithm at the beginning of aux file \jobname.loa, which is input by \@starttoc{\@nameuse{ext@#1}} in \listof.

\documentclass{scrbook}
\usepackage{algorithm}

\makeatletter \renewcommand\l@figure{@dottedtocline{1}{0em}{2.3em}}

\addtocontents{loa}{% \protect\renewcommand\protect\l@algorithm{\protect@dottedtocline{1}{0em}{2.3em}}% \protected@file@percent% } \makeatother

\begin{document}

\begin{algorithm} \caption{An algorithm} \end{algorithm}

\begin{figure} \caption{A figure} \end{figure}

\listoffigures \listofalgorithms

\end{document}

outpuf of \listoffigures output of \listofalgorithms

muzimuzhi Z
  • 26,474