我正在准备的书的目录需要额外的格式。我正在 KOMA-scriptscrbook
课上工作。这本书包含大量讲座,我将其视为章节,其中一些以名为“问题和答案”的部分结尾。我的问题是点填充了目录中章节标题和页码之间的空间。对于早期帮助并跟进 帮助,我找到了答案这里,以下是我的 MWE。不过,我还不满意的是,导致目录中的点错位。
\DeclareTOCStyleEntry[
linefill={},
]{tocline}{chapter}
\makeatletter
\newcommand \Dotfill {\leavevmode \cleaders \hb@xt@ 0.83em{\hss .\hss }\hfill \kern \z@}
\makeatother
\newcommand{\toclineinsert}[3][14mm]{%
\Dotfill #2\makebox[#1][l]{#3\Dotfill}%
}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\addchap
[tocentry={Second lecture title \toclineinsert{\normalfont{2nd half January}}},head={}]
{Second lecture title}
\lipsum[1-20]
\addsec[tocentry={Questions and answers},head={}]{}
一定有比调整部分命令em
的 -size更好的方法来使 ToC 中的点匹配。\hb@xt@
\Dotfill
答案1
使用 KOMA-Script 类,scrbook
目录中章节(和子章节等)条目的默认行填充是\TOCLineLeaderFill
。点之间的距离取决于点的大小和字体。因此您必须使用
\newcommand\Dotfill{{\normalfont\normalsize \TOCLineLeaderFill}}
然后,章节标题和日期之间的点与节标题后的点对齐。
但是日期和页码之间的点与章节条目的点很难对齐。这里有一个建议,但仍然需要根据字体大小和进行调整\@dotfil
。
\documentclass[headings=optiontotocandhead]{scrbook}
\usepackage{lipsum}% only for dummy text
\DeclareTOCStyleEntry[
linefill={},
]{tocline}{chapter}
\newcommand\Dotfill{{\normalfont\normalsize \TOCLineLeaderFill}}
\newlength{\leaderboxwidth}
\setlength{\leaderboxwidth}{43.8pt}% <- adjust here
\DeclareRobustCommand*{\toclineinsert}[1]{%
{\normalfont\Dotfill {#1}\makebox[\leaderboxwidth][l]{\Dotfill}}%
}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\addchap
[tocentry={First lecture title \toclineinsert{4 January}},head={}]
{Second lecture title}
\lipsum[1-20]
\addsec[tocentry={Questions and answers},head={}]{}
\addchap
[tocentry={Second lecture title \toclineinsert{2nd half January}},head={}]
{Second lecture title}
\lipsum[1-20]
\addsec[tocentry={Questions and answers},head={}]{}
\addchap
[tocentry={Third lecture title \toclineinsert{Arpil/March}},head={}]
{Third lecture title}
\addsec[tocentry={Questions and answers},head={}]{}
\end{document}
\documentclass[headings=optiontotocandhead]{scrbook}
\usepackage{lipsum}% only for dummy text
\DeclareTOCStyleEntry[
linefill=\TOCLineLeaderFill,
raggedentrytext=true
]{tocline}{chapter}
\DeclareRobustCommand*{\toclineinsert}[1]{{\ \normalfont\mbox{(#1)}}}
\begin{document}
\tableofcontents
\addchap
[tocentry={first lecture title \toclineinsert{4 January}}]
{first lecture title}
\lipsum[1-20]
\addsec[tocentry={Questions and answers},head={}]{}
\addchap
[tocentry={second lecture title \toclineinsert{2nd half January}},head={different entry in page header}]
{second lecture title}
\lipsum[1-20]
\addsec[tocentry={Questions and answers},head={}]{}
\addchap
[tocentry={third lecture title \toclineinsert{February/March}}]
{third lecture title}
\addsec[tocentry={Questions and answers},head={}]{}
\end{document}
但我建议使用
\documentclass[headings=optiontotocandhead]{scrbook}
\usepackage{lipsum}% only for dummy text
\DeclareTOCStyleEntry[
linefill=\TOCLineLeaderFill,
raggedentrytext=true
]{tocline}{chapter}
\DeclareRobustCommand*{\toclineinsert}[1]{{\normalfont\mbox{(#1)}}}
\begin{document}
\tableofcontents
\addchap
[tocentry={first lecture title \toclineinsert{4 January}}]
{first lecture title}
\lipsum[1-20]
\addsec[tocentry={Questions and answers},head={}]{}
\addchap
[tocentry={second lecture title \toclineinsert{2nd half January}},head={different entry in page header}]
{second lecture title}
\lipsum[1-20]
\addsec[tocentry={Questions and answers},head={}]{}
\addchap
[tocentry={third lecture title \toclineinsert{February/March}}]
{third lecture title}
\addsec[tocentry={Questions and answers},head={}]{}
\end{document}
或者
\documentclass[headings=optiontotocandhead]{scrbook}
\usepackage{lipsum}% only for dummy text
\DeclareTOCStyleEntry[
linefill={},
]{tocline}{chapter}
\newcommand \Dotfill {{\normalfont\normalsize \TOCLineLeaderFill}}
\DeclareRobustCommand*{\toclineinsert}[1]{%
{\normalfont\Dotfill\mbox{#1\quad}}%
}
\begin{document}
\tableofcontents
\addchap
[tocentry={first lecture title \toclineinsert{4 January}}]
{first lecture title}
\lipsum[1-20]
\addsec[tocentry={Questions and answers},head={}]{}
\addchap
[tocentry={second lecture title \toclineinsert{2nd half January}},head={different entry in page header}]
{second lecture title}
\lipsum[1-20]
\addsec[tocentry={Questions and answers},head={}]{}
\addchap
[tocentry={third lecture title \toclineinsert{February/March}}]
{third lecture title}
\addsec[tocentry={Questions and answers},head={}]{}
\end{document}