0

Because of this answer to Extending table of contents dots up to large page numbers I am using tocbasic and would like to add more spacing between the reference numbers in the

  • List of listings
  • List of algorithms

and the captions. I have been using this solution

\usepackage{tocbasic}
\DeclareTOCStyleEntry[numwidth=3.5em]{tocline}{figure}% for figure entries
\DeclareTOCStyleEntry[numwidth=3.5em]{tocline}{table}% for table entries

to Spacing problem at List of Figures.

How can I add some spacing between the numbers and the entries?

enter image description here

enter image description here

\documentclass{book}
\usepackage[algosection]{algorithm2e} % For writing nice algorithms. 
\usepackage{etoolbox}
\usepackage{float}  %% The ordering matters here. 
\usepackage{listings} %% The ordering matters here. 
\usepackage{lipsum}
\usepackage{tocbasic} % For better TOC alignment
\usepackage[nottoc]{tocbibind} 
\usepackage{todonotes}
\usepackage[margin=10pt,font=small,labelfont=bf,labelsep=endash,figurewithin=section,tablewithin=section]{caption} % Caption figures and tables nicely. %% After cleveref.

% List of Algorithms (NB, requires french spelling of 'algorithmes')
\renewcommand*{\listalgorithmcfname}{List of algorithms}
\newcommand{\listofalgorithmes}{\tocfile{\listalgorithmcfname}{loa}}

% We want the list of listings to look like all the others. 
\let\Chapter\chapter
\def\chapter{\addtocontents{lol}{\protect\addvspace{10pt}}\Chapter}
\makeatletter
\patchcmd{\@chapter}{\chaptermark{#1}}{%
    \chaptermark{#1}%
    \addtocontents{lol}{\protect\addvspace{10\p@}}%
}{\typeout{Chapters patched for list-of-listings.}}{\typeout{Could not patch chapters for list-of-listings.}}
\makeatother

% So Roman page numbers are right aligned. 
\DeclareTOCStyleEntries[
  rightindent=10em,
  pagenumberbox=\pagenumberbox
]{tocline}{section,subsection,subsubsection,paragraph,subparagraph,figure,table}
\newcommand*\pagenumberbox[1]{\mbox{\hspace{1em}#1}}


\DeclareTOCStyleEntry[numwidth=3.5em]{tocline}{figure}% for figure entries
\DeclareTOCStyleEntry[numwidth=3.5em]{tocline}{table}
%\DeclareTOCStyleEntry[numwidth=3.5em]{tocline}{listing}% <- Doesn't work
%\DeclareTOCStyleEntry[numwidth=3.5em]{tocline}{algorithm}% <- Doesn't work

\AtBeginDocument{\counterwithin{lstlisting}{section}} % Ensures these are numbered enough

\setcounter{secnumdepth}{3}

\begin{document}
\tableofcontents
\listoffigures
\listoftables
\lstlistoflistings
\listofalgorithmes
\listoftodos   
\cleardoublepage
\pagenumbering{arabic}
\section{Arabic numbering starts}
\subsection{Some possibly very long title section that might just decide to span several lines in the table of contents. Why would someone write this, Who knows?}
\lipsum
\cleardoublepage
\setcounter{page}{123456789}
\section{Several pages later}
\subsection{Something}
\lipsum
\cleardoublepage
\pagenumbering{Roman}
\section{Now we have Roman numbering}
\subsection{Something}
\lipsum
\clearpage
\setcounter{page}{123}
\section{Several pages later}
\subsection{Something}
\lipsum
\chapter{title}
\section{Some figures}
\subsection{title}
\subsubsection{title}
\begin{figure}[htb]\caption{something}\end{figure}
\begin{figure}[htb]\caption{something}\end{figure}
\begin{figure}[htb]\caption{something}\end{figure}
\begin{figure}[htb]\caption{something}\end{figure}
\begin{figure}[htb]\caption{something}\end{figure}
\chapter{Chapter}
\section{Section}\section{Section}\section{Section}
\begin{table}[htb]\caption{A table}\end{table}
\begin{figure}[htb]\caption{A figure}\end{figure}
\begin{lstlisting}[caption={Some code}]
\end{lstlisting}
\todo[inline=true,caption={A todo note}]{Must do this.}
\begin{algorithm}[htb] \DontPrintSemicolon \KwIn{Input} \KwOut{Output} Code\; \caption{Some algorithm.} \end{algorithm}
\begin{table}[htb]\caption{A table}\end{table}
\begin{figure}[htb]\caption{A figure}\end{figure}
\begin{lstlisting}[caption={Some code}]
\end{lstlisting}
\todo[inline=true,caption={A todo note}]{Must do this.}
\begin{algorithm}[htb] \DontPrintSemicolon \KwIn{Input} \KwOut{Output} Code\; \caption{Some algorithm.} \end{algorithm}
\begin{table}[htb]\caption{A table}\end{table}
\begin{figure}[htb]\caption{A figure}\end{figure}
\begin{lstlisting}[caption={Some code}]
\end{lstlisting}
\todo[inline=true,caption={A todo note}]{Must do this.}
\begin{algorithm}[htb] \DontPrintSemicolon \KwIn{Input} \KwOut{Output} Code\; \caption{Some algorithm.} \end{algorithm}
\chapter{Chapter}
\section{Section}\section{Section}\section{Section}
\begin{table}[htb]\caption{A table}\end{table}
\begin{figure}[htb]\caption{A figure}\end{figure}
\begin{lstlisting}[caption={Some code}]
\end{lstlisting}
\todo[inline=true,caption={A todo note}]{Must do this.}
\begin{algorithm}[htb] \DontPrintSemicolon \KwIn{Input} \KwOut{Output} Code\; \caption{Some algorithm.} \end{algorithm}
\begin{table}[htb]\caption{A table}\end{table}
\begin{figure}[htb]\caption{A figure}\end{figure}
\begin{lstlisting}[caption={Some code}]
\end{lstlisting}
\todo[inline=true,caption={A todo note}]{Must do this.}
\begin{algorithm}[htb] \DontPrintSemicolon \KwIn{Input} \KwOut{Output} Code\; \caption{Some algorithm.} \end{algorithm}
\begin{table}[htb]\caption{A table}\end{table}
\begin{figure}[htb]\caption{A figure}\end{figure}
\begin{lstlisting}[caption={Some code}]
\end{lstlisting}
\todo[inline=true,caption={A todo note}]{Must do this.}
\begin{algorithm}[htb] \DontPrintSemicolon \KwIn{Input} \KwOut{Output} Code\; \caption{Some algorithm.} \end{algorithm}
\end{document}

Solution for algorithms

Taken from this answer to List of Algorithms: space between number and algorithm caption too small.

\makeatletter
\renewcommand*\l@algocf{\@dottedtocline{1}{1em}{3.2em}}% Original {1}{1em}{2.3em}
\makeatother

which gives

enter image description here

1 Answer 1

1

You could use

\usepackage{tocbasic}[2019/12/23]

\DeclareTOCStyleEntry[numwidth=3.5em]{tocline}{figure}
\DeclareTOCStyleEntries[
  level:=figure,
  indent:=figure,
  numwidth:=figure,
]{tocline}{table,lstlisting,algocf,todo}
\DeclareTOCStyleEntries[
  rightindent=10em,
  pagenumberbox=\pagenumberbox
]{tocline}{section,subsection,subsubsection,paragraph,subparagraph,figure,table,lstlisting,algocf,todo}
\newcommand*\pagenumberbox[1]{\mbox{\hspace{1em}#1}}

Or you could use dynnumwidth:

\usepackage{tocbasic}[2019/12/23]

\DeclareTOCStyleEntry[dynnumwidth]{tocline}{figure}
\DeclareTOCStyleEntries[
  level:=figure,
  indent:=figure,
  numwidth:=figure,
  dynnumwidth
]{tocline}{table,lstlisting,algocf,todo}
\DeclareTOCStyleEntries[
  rightindent=10em,
  pagenumberbox=\pagenumberbox
]{tocline}{section,subsection,subsubsection,paragraph,subparagraph,figure,table,lstlisting,algocf,todo}
\newcommand*\pagenumberbox[1]{\mbox{\hspace{1em}#1}}

dynnumwidth enlarges the space for the entry number automatically, if the entry number is too long. But it needs an additional run. Then you can use numsep to adjust the minimum space between the entry number and the entry text:

\usepackage{tocbasic}[2019/12/23]

\DeclareTOCStyleEntry[
  numsep=2em,
  dynnumwidth
]{tocline}{figure}
\DeclareTOCStyleEntries[
  level:=figure,
  indent:=figure,
  numwidth:=figure,
  numsep:=figure,
  dynnumwidth
]{tocline}{table,lstlisting,algocf,todo}
\DeclareTOCStyleEntries[
  rightindent=10em,
  pagenumberbox=\pagenumberbox
]{tocline}{section,subsection,subsubsection,paragraph,subparagraph,figure,table,lstlisting,algocf,todo}
\newcommand*\pagenumberbox[1]{\mbox{\hspace{1em}#1}}

You must log in to answer this question.

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