使用 svmono 时,如何在目录中的标题和页码之间自动创建适当量的水平空间?

使用 svmono 时,如何在目录中的标题和页码之间自动创建适当量的水平空间?

喂食

\documentclass[deutsch]{svmono}% taken from https://resource-cms.springernature.com/springer-cms/rest/v1/content/20566/data/monographs
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[helvratio=.9]{newtxtext}% we use this in a non-minimal example
\usepackage[hidelinks]{hyperref}% we use this in a non-minimal example
\usepackage{lastpage}
\usepackage{calc}
\setcounter{tocdepth}{4}% to which depth the titles should occur in the table of contents. 4 means: paragraph titles occur in the table of contents, but not subparagraph titles.
\setcounter{secnumdepth}{4}% to which depth the numbering should occur. 4 means: paragraphs are numbered but not subparagraphs.
\begin{document}
\selectlanguage{ngerman}%%% cf. http://tex.stackexchange.com/a/252847
\pagenumbering{Roman}
\author{Autor}
\title{Titel}
\maketitle
\frontmatter
\makeatletter
%\renewcommand{\@pnumwidth}{1.8em}%% standard is 1.55em. Works but is fixed and might need an adjustment when the number of pages changes.
%%% cumbersome:
% \newlength{\Tmp}
% \setlength{\Tmp}{\widthof{\pageref*{LastPage}} + \fontdimen2*2/3}%%% doesn't work, dunno why
% \setlength{\Tmp}{\widthof{\pageref*{LastPage}}+\widthof{\ }*2/3}
% \renewcommand{\@pnumwidth}{\Tmp}
\makeatother
\tableofcontents
\mainmatter
\setcounter{page}{400}
\part{xxxxxxxxxxxxx xxxxxxxxxxxxx xxxxxxxxxxxxx xxxxxxxxxxxxx xxxxxxx}
\chapter{xxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxxxxx}
\section{xxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxx xxxxxxxxxx}
\subsection{xxxxxxxxxx xxxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx}
\subsubsection{xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx}
\paragraph{xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxx}
\end{document}

得到pdflatex下面的目录:

目录

我们看到,标题和页码之间没有水平间距。这很糟糕。

添加水平空间的一种方法是手动设置\@pnumwidth为固定长度。但是,每次总页数的位数发生变化时,我们都需要考虑更改此宏。

另一种方法是计算最后一页的页码,取其宽度,添加(例如)空格宽度的 2/3,将其放入长度中,然后将该长度分配给\@pnumwidth。这似乎过于麻烦。还有其他更优雅的方法吗?(我不想使用,tocloft因为它会更改类的默认值svmono。)我们真的需要lastpage还是hyperref它本身会计算最后一页的页码?我们真的需要仅为计算目的分配临时长度吗?

总结一下,如何简洁的计算并在标题和页码之间添加适当的水平空间?

相关内容