语境:我已经自定义了文档中目录的布局scrbook
。除了与部分相关的条目外,它看起来很棒。事实上,如果相关页码大于 100,则页码水平对齐不齐。这不是由于部分标题太长造成的,如您在下面的 MWE 中看到的那样。我还确保禁用了突起来排版目录。
问题:如何右对齐所有页码?
平均能量损失
\documentclass[a5paper]{scrbook}
\usepackage{lipsum}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{microtype}
\KOMAoption{listof}{%
indented,%
smallchaptergap,%
}
%-- ToC layout --
\KOMAoptions{toc=chapterentrydotfill}
\addtokomafont{chapterentry}{\mdseries}
\addtokomafont{chapterentrypagenumber}{\mdseries}
\DeclareTOCStyleEntry[beforeskip=1em plus 1pt, numwidth=1.3em]{default}{part}
\DeclareTOCStyleEntry[beforeskip=0pt plus .2pt, indent=1.3em, numwidth=1.5em]{default}{chapter}
\begin{document}
\microtypesetup{protrusion=false}
\tableofcontents
\microtypesetup{protrusion=true}
%Dummy text below
\part{First part}
\chapter{A first chapter}
\lipsum[1-42]
\chapter{A second chapter}
\lipsum[43-90]
\chapter{A third chapter}
\lipsum[91-150]
\part{Second part}
\chapter{Another first chapter}
\lipsum[1-42]
\chapter{Another second chapter}
\lipsum[43-90]
\chapter{Another third chapter}
\lipsum[91-150]
\lipsum[80-150]
\part{Third part}
\chapter{Still a first chapter}
\lipsum[1-42]
\chapter{Still a second chapter}
\lipsum[43-90]
\chapter{Still a third chapter}
\lipsum[91-150]
\part{Fourth empty part}
\end{document}
答案1
需要调整的关键变量是\renewcommand\@pnumwidth{<width of page number field>}
。这里我将其设置为2em
。
\documentclass[a5paper]{scrbook}
\usepackage{lipsum}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{microtype}
\KOMAoption{listof}{%
indented,%
smallchaptergap,%
}
%-- ToC layout --
\KOMAoptions{toc=chapterentrydotfill}
\addtokomafont{chapterentry}{\mdseries}
\addtokomafont{chapterentrypagenumber}{\mdseries}
\DeclareTOCStyleEntry[beforeskip=1em plus 1pt, numwidth=1.3em]{default}{part}
\DeclareTOCStyleEntry[beforeskip=0pt plus .2pt, indent=1.3em, numwidth=1.5em]{default}{chapter}
\makeatletter
\renewcommand\@pnumwidth{2em}
\makeatother
\begin{document}
\microtypesetup{protrusion=false}
\tableofcontents
\microtypesetup{protrusion=true}
%Dummy text below
\part{First part}
\chapter{A first chapter}
\lipsum[1-42]
\chapter{A second chapter}
\lipsum[43-90]
\chapter{A third chapter}
\lipsum[91-150]
\part{Second part}
\chapter{Another first chapter}
\lipsum[1-42]
\chapter{Another second chapter}
\lipsum[43-90]
\chapter{Another third chapter}
\lipsum[91-150]
\lipsum[80-150]
\part{Third part}
\chapter{Still a first chapter}
\lipsum[1-42]
\chapter{Still a second chapter}
\lipsum[43-90]
\chapter{Still a third chapter}
\lipsum[91-150]
\part{Fourth empty part}
\end{document}
我是从包装文档中的一张图中了解到这个事实的tocloft
,https://ctan.org/pkg/tocloft,如第 3 页所示: