算法解决方案

算法解决方案

因为这个答案将目录点扩展到大页码我正在使用tocbasic并希望在参考编号之间添加更多间距

  • 列表列表
  • 算法列表

和标题。我一直在使用此解决方案

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

图片列表的间距问题

我如何在数字和条目之间添加一些空格?

在此处输入图片描述

在此处输入图片描述

\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}

算法解决方案

取自这个答案算法列表:数字和算法标题之间的间距太小

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

这使

在此处输入图片描述

答案1

你可以使用

\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}}

或者你可以使用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如果条目编号太长,则会自动扩大条目编号的空间。但需要额外运行一次。然后您可以使用来numsep调整条目编号和条目文本之间的最小间距:

\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}}

相关内容