TOCLOFT 和前導點...停用單點或無點

TOCLOFT 和前導點...停用單點或無點

在設計我的論文時,出版商要求目錄中至少有兩個點 - 否則需要斷開該行(手動完成會導致其他問題)。有沒有什麼想法可以創建比tocloft \renewcommand\cftdotsep{..}-thing 更優雅的解決方案(這會​​在其他行產生新問題)?

微量元素:

\documentclass[
paper=233mm:155mm,
fontsize=10.5,
cleardoubleempty,
headings=optiontohead,
bibliography=totoc,
idxtotoc,
pointlessnumbers]
{scrbook}


\usepackage{fontspec}
\setmainfont{Times New Roman}

\usepackage{polyglossia}  % Sprachumschaltung
\setdefaultlanguage{german}% Voreingestellte Dokumentsprache: Deutsch


%%% Seitenränder etc.
\usepackage[footnotesep=1.5\baselineskip]{geometry}
\geometry{includehead=true, textwidth=117mm, textheight=186mm, headsep=6mm, left=18mm, bottom=24mm}


%% Design der Überschriften %%%%%%%%%%
\setkomafont{sectioning}{\normalfont\large\scshape\centering}
\setkomafont{part}{\normalfont\Huge\scshape\centering}
\setkomafont{chapter}{\normalfont\LARGE\scshape\centering}
\setkomafont{section}{\normalfont\Large\centering}
\setkomafont{subsection}{\normalfont\large\centering}
\setkomafont{subsubsection}{\normalfont\normalsize\centering}
\setkomafont{minisec}{\normalfont\normalsize\itshape\centering}
\setkomafont{paragraph}{\normalfont\normalsize\itshape}
\setkomafont{subparagraph}{\normalfont\normalsize\itshape}


%% Inhaltsverzeichnis formatieren %%%%%%%%%%%%%%%%%%%
\usepackage{tocloft}

\tocloftpagestyle{empty} %keine Seitenzahl auf erster Seite des Inhaltsverzeichnisses

\renewcommand{\cftchappagefont}{} % Seitenzahlen auch bei Chapter nicht fett
\renewcommand{\cftpartpagefont}{} % Seitenzahlen auch bei Chapter nicht fett

\renewcommand{\cftchapleader}{\cftdotfill{\cftchapdotsep}} % Punkte nicht fett
\renewcommand{\cftchapdotsep}{\cftdotsep}

\renewcommand{\cfttoctitlefont}{\hfill\normalfont\LARGE\scshape} % Größe der Überschrift wie \chapter
\renewcommand{\cftaftertoctitle}{\hfill}

\renewcommand{\cftchapfont}{\normalfont}  %% Im Inhaltsverzeichnis Titel normal. alternativ fett. \bfseries
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}

\renewcommand\thesection{\thechapter.\arabic{section}}   %% Nummerierung Section Römisch

\renewcommand\thesubsection{\thesection.\arabic{subsection}} %% Nummerierung Subsection arabisch usw.

\renewcommand\thesubsubsection{\thesubsection.\arabic{subsubsection}}

\usepackage{blindtext}

\begin{document}

\tableofcontents

\chapter{A chapter with a title much too long as there aren't any dots any more}
\blindtext

\section{A section that is ok as there are at least two dots left}
\blindtext

\subsection{A subsection again not fitting as it is only ONE dot left}
\blindtext

\end{document}

答案1

一種方法是直接修補\@dottedtocline內部命令,以便它產生至少兩個 em 長的領導者(例如):

\documentclass{scrbook}

\makeatletter

\renewcommand*\@dottedtocline[5]{%
  \ifnum #1>\c@tocdepth \else
    \vskip \z@ \@plus.2\p@
    {\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
     \parindent #2\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima #3\relax
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {#4}\nobreak
     \leaders\hbox{$\m@th
        \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
        mu$}\hskip 2em \@plus 1fill % <<< PATCH
     \nobreak
     \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #5}%
     \par}%
  \fi}

\makeatother

\begin{document}

\tableofcontents

\chapter{One}
Lorem ipsum.

\section{Some words to fill the line, words to fill the line,
    words to fill the line}
Dolor sit amet.

\section{Some words to fill the line, words to fill the line,
    words to fill the line, w}
Consectetur adipisci elit.

\section{Some words to fill the line, words to fill the line,
    words to fill the line, wo}
Numquam faucibus,.

\end{document}

這倆抄寫本類別最終會呼叫\@dottedtocline以與領導者一起產生目錄條目,因此補丁應該可以工作。

輸出:

範例程式碼的輸出

添加

我忘了提及,一如既往,\patchcmd飯店提供的設施電子工具箱可以使用 package 代替\renewcommand(需要重複完整的定義):

\documentclass{scrbook}
\usepackage{etoolbox}

\makeatletter
\patchcmd{\@dottedtocline}{\hfill}{\hskip 2em \@plus 1fill }{}{}
\makeatother

\begin{document}

\tableofcontents

\chapter{One}
Lorem ipsum.

\section{Some words to fill the line, words to fill the line,
    words to fill the line}
Dolor sit amet.

\section{Some words to fill the line, words to fill the line,
    words to fill the line, w}
Consectetur adipisci elit.

\section{Some words to fill the line, words to fill the line,
    words to fill the line, wo}
Numquam faucibus,.

\end{document}

第二次補充

評論需要為以下內容量身定制類似的補丁托克洛夫特包裹。快速檢查發現,該套件並不依賴\@dottedtocline產生領導者,而是定義了自己的命令,即\cftdotfillfor the Purpose。因此,在這種情況下必須修補以下命令:

\documentclass{scrbook}
\usepackage{tocloft}

\makeatletter

\renewcommand{\cftdotfill}[1]{%
  \def\@tempa{#1}%
  \def\@tempb{\cftnodots}%
  \ifx\@tempa\@tempb
    \hfill % <<< this has not been changed
  \else
    \leaders\hbox{$\m@th\mkern #1 mu\hbox{\cftdot}\mkern #1 mu$}%
      \hskip 2em \@plus 1fill \relax % <<< PATCH
  \fi
}

\makeatother

\begin{document}

\tableofcontents

\chapter{One}
Lorem ipsum.

\section{Some words to fill the line, words to fill the line,
    words to fill the line}
Dolor sit amet.

\section{Some words to fill the line, words to fill the line,
    words to fill the line, w}
Consectetur adipisci elit.

\section{Some words to fill the line, words to fill the line,
    words to fill the line, wo}
Numquam faucibus,.

\end{document}

答案2

高德納和普拉斯 1981 年「將段落分成行」解釋了 TeX 斷行演算法底層的盒子和膠水模型,並展示了它所啟用的一些煙火技術。

使用這些技巧之一,我們可以設定一個更雄心勃勃的目標:當前導符和頁碼由於空間不足而放置在自己的行中時,用前導符填充前一行,使其與右側的固定邊距以內。

請注意當我們強制添加一條額外的線時,前導者右邊緣的匹配方式。

您可以透過調整 來控制額外的引線突出到下一行出現的頁碼上方的右邊距的程度\rmargin

在此輸入影像描述

\documentclass[a5paper]{article}     

\usepackage{fontspec}

\setmainfont{Times New Roman}

\parindent=0pt % optional, mimick TOC environment

\newdimen\pagenumwidth \pagenumwidth=0.5cm  % reserved right margin space for page numbers
                                                                                  % leaders will reach flush with it 
\newdimen\rmargin \rmargin=0.5cm  % reserved right margin for leaders followed by linbreal
\newdimen\minspc \minspc=1.6em    % if this much hspace isn't available for leaders, break                                                

\def\fillwith{\hbox to 1ex {\hss.\hss}} 

\def\DotsAndPage#1{%
    \leaders\fillwith\hfil
    \hskip \rmargin 
    \penalty50  
    \hskip - \rmargin plus -1fil  % Thanks Gustavo
    \hbox{}      
    \unskip\leaders\fillwith\hskip \minspc plus 1fill
    \nobreak
    {\bfseries\normalsize \hbox to \pagenumwidth{\hfil#1}}%
    \break}

\begin{document}  

{
\hsize=2.4in
A chapter with a title any \DotsAndPage{1}%\par
A chapter with a title A chapter with a title A chapter with a title\DotsAndPage{13}%\par
A chapter with a title A chapter with a title A chapter with a title with a title so t\DotsAndPage{132}
A chapter with a title A chapter with a title A chapter with a title with a title so th\DotsAndPage{132}
\rmargin=0.25cm % leaders tail bite into right margin
A chapter with a title with a title so th\DotsAndPage{132}
\rmargin=-0.1cm  
A chapter with a title with a title so th\DotsAndPage{132}\par      
}


\end{document}

相關內容