tocloft 出了点问题

tocloft 出了点问题

我希望目录的右边距是直的。但 Latex 却违反了界限(图 1)。如果注释掉 babel(使用最后一个 \addcontentsline),结果仍然有问题(图 2)。显然,即使没有连字符,某些单词也可以延续到下一行。

这是最小的工作示例。

\documentclass{book}
\usepackage[russian]{babel}
\usepackage[titles]{tocloft}

\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\cftsetrmarg{4cm}

\begin{document}
  \tableofcontents

  \addcontentsline{toc}{chapter}{Well it certainly is better if you activate the hyphenation pattern for french. This will "split" the berger. It also helps if you remove the stretchable space in the spacing command inserted  Well it certainly is better if you activate the hyphenation pattern for french. This will "split" the berger. It also helps if you remove the stretchable space in the spacing command inserted }

  \addcontentsline{toc}{chapter}{Blossom blossom blossom blossom blossom blossom test test test blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom}

  \addcontentsline{toc}{chapter}{Bbbbbbb bbbbbbbbbb bbbbbbb bbbbbbbbbb bbbbbb}

  \addcontentsline{toc}{chapter}{Численные исследования разработанных алгоритмов}

\end{document}

图 1

图片 1 (上图)。

图2

图片 2(上图)。

更新。

提出的解决方案部分解决了该问题。其余问题如图 3 所示。相应的代码为:

\documentclass{book}
\usepackage[english]{babel}
\usepackage[titles]{tocloft}

% Compulsory settings
\textwidth=170mm
\cftsetrmarg{6.35cm}

% Adviced (but not working) options
\renewcommand{\cftchapleader}{\penalty5000 \cftdotfill{\cftdotsep}}
\emergencystretch=10em
\sloppy


\begin{document}
  \tableofcontents

  \addcontentsline{toc}{chapter}{This line just demonstrates the right bound. Well it certainly is better if you activate the hyphenation pattern for french. This will "split" the berger. It also helps if you remove the stretchable space in the spacing command inserted  Well it certainly is better if you activate the hyphenation pattern for french. This will "split" the berger. It also helps if you remove the stretchable space in the spacing command inserted }

  \addcontentsline{toc}{chapter}{Thisline demonstratesdemonstrates thewidthof posbbbbbbbbbbbbbbblegaps. Thisline demonstrates thewidthof possiblegaps.}

  \addcontentsline{toc}{chapter}{Parameter parmeter parameter parammmeter Fibre Channel}

\end{document}

图 3

图 3(上图)。

答案1

基本上我认为你的要求是领导者至少 \rightskip的长度,并且它们的长度绝不会缩短到小于这个长度,因此允许最后一行延长。

因此,您需要一个修改过的领导者命令,该命令总是插入至少那么多的点:

在此处输入图片描述

\documentclass{book}
\usepackage[english]{babel}
\usepackage[titles]{tocloft}

% Compulsory settings
\textwidth=170mm
\cftsetrmarg{6.35cm}

\makeatletter
\providecommand{\cftdotfillb}[1]{%
  \leaders\hbox{$\m@th\mkern #1 mu\hbox{\cftdot}\mkern #1 mu$}\hskip 1\rightskip plus 1fill}

% Adviced (but not working) options
\renewcommand{\cftchapleader}{\cftdotfillb{\cftdotsep}}

\makeatother

\begin{document}
  \tableofcontents

\sloppy
\emergencystretch3em

  \addcontentsline{toc}{chapter}{This line just demonstrates the right bound. Well it certainly is better if you activate the hyphenation pattern for french. This will "split" the berger. It also helps if you remove the stretchable space in the spacing command inserted  Well it certainly is better if you activate the hyphenation pattern for french. This will "split" the berger. It also helps if you remove the stretchable space in the spacing command inserted }

  \addcontentsline{toc}{chapter}{Thisline demonstratesdemonstrates thewid\-thof pos\-bbbbb\-bb\-bbbbbbbblegaps. Thisline demonstrates thewidthof possiblegaps.}

  \addcontentsline{toc}{chapter}{Parameter parmeter parameter parammmeter Fibre Channel}

  \addcontentsline{toc}{chapter}{Parameter parmeter  Fibre Channel}

\end{document}

原始答案

我不确定它是否真的是 babel;我似乎没有安装 babel cyrilic 支持,因此无法复制所有情况,但即使根本没有加载 babel,也可以演示重复的 bbb 情况。

如果你允许的话,最好换队,但强烈反对在领队之前换队

\renewcommand{\cftchapleader}{\penalty5000 \cftdotfill{\cftdotsep}}

在此处输入图片描述

答案2

切换到正确的语言并修改\emergencystretch。但是,您不应该设置cftsetrmarg。使用默认值可以获得更好的结果。

\documentclass{book}
\usepackage[english,russian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[titles]{tocloft}

\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\cftsetrmarg{4cm}

\begin{document}
\begingroup
\emergencystretch=2em
  \tableofcontents
\endgroup

  \addcontentsline{toc}{chapter}{\protect\foreignlanguage{english}{Well it certainly is better if you activate the hyphenation pattern for french. This will "split" the berger. It also helps if you remove the stretchable space in the spacing command inserted  Well it certainly is better if you activate the hyphenation pattern for french. This will "split" the berger. It also helps if you remove the stretchable space in the spacing command inserted }}

  \addcontentsline{toc}{chapter}{\protect\foreignlanguage{english}{Blossom blossom blossom blossom blossom blossom test test test blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom}}

  \addcontentsline{toc}{chapter}{\protect\foreignlanguage{english}{Bbbbbbb bbbbbbbbbb bbbbbbb bbbbbbbbbb bbbbbb}}

  \addcontentsline{toc}{chapter}{Численные исследования разработанных алгоритмов}

\end{document}

在此处输入图片描述

答案3

似乎仅当目录条目跨越多行时才会从右侧添加空格,因此您的示例可能没问题。

如果你真的希望所有线条的宽度相同,则可以使用提供的解决方案大卫·卡莱尔

如果您有多行俄语和英语条目,则应手动选择正确的语言以\selectlanguage启用连字符。请参阅\selectlanguage{russian}俄语内容条目之前的内容。

\documentclass{book}
\usepackage[russian,english]{babel}
\usepackage[T1,T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[titles]{tocloft}

\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\cftsetrmarg{4cm}

\begin{document}
  \tableofcontents

  \addcontentsline{toc}{chapter}{Well it certainly is better if you activate the hyphenation pattern for french. This will "split" the berger. It also helps if you remove the stretchable space in the spacing command inserted  Well it certainly is better if you activate the hyphenation pattern for french. This will "split" the berger. It also helps if you remove the stretchable space in the spacing command inserted }

  \addcontentsline{toc}{chapter}{Blossom blossom blossom blossom blossom blossom test test test blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom blossom}

  \addcontentsline{toc}{chapter}{Bbbbbbb bbbbbbbbbb bbbbbbb bbbbbbbbbb bbbbbb}
\selectlanguage{russian}

  \addcontentsline{toc}{chapter}{Численные исследования разработанных алгоритмов Численные исследования разработанных алгоритмов Численные исследования разработанных алгоритмов}

\end{document}

在此处输入图片描述

相关内容