请不要在目录条目中使用连字符

请不要在目录条目中使用连字符

我有一些非常长的章节标题,并且不希望目录中的条目使用连字符。 示例输出

\documentclass{scrreprt}
%\usepackage[ngerman]{babel}
\usepackage{tocloft}
\cftsetindents{section}{0mm}{12mm}
\cftsetindents{chapter}{0mm}{12mm}

\begin{document}
\tableofcontents
\chapter{Introduction}
\section{This kind of problem, that kind of problem, other ones and further considerations}
\section{More problems, even more problems, much worse than these, headline hyphenation, and blablablablablablablablabla and XYZ-blablablablablablablablabla}
\end{document}

通过谷歌搜索,我得到的印象是\renewcommand{\cftsecfont}{\raggedright}应该有帮助,但事实并非如此\begingroup \raggedright \tableofcontents \endgroup相关问题的唯一(未被接受的)答案。(有趣的是,当我取消注释时\usepackage{ngerman]{babel},“consider-erations”的连字符会变为“considerations”。)

当我不使用tocloft或将文档类别更改为时book,也会出现此问题(例如,在不同的音节上使用连字符)。

我能否让目录中的连字符完全消失,而无需为每个有问题的单词重新定义它?!如果解决方案不会让长单词越过行线(如最后的“blabla...”),则可以获得加分;如果以连字符开头的单词组合(“XYZ-blabla”)可以放在同一行,则可以获得更多加分。

答案1

由于你使用的是 KOMA 类,因此可以使用tocstyle包裹:

在此处输入图片描述

代码:

\documentclass{scrreprt}
\usepackage[ngerman]{babel}
\usepackage[tocflat]{tocstyle}

\newtocstyle{raggedstyle}{%
  \settocstylefeature[0]{entryhook}{\bfseries}
  \settocstylefeature[0]{leaders}{\hfill}
  \settocfeature{raggedhook}{\raggedright}
  \settocfeature{spaceafternumber}{17pt}
}
\usetocstyle{raggedstyle}

\begin{document}

\tableofcontents

\chapter{Introduction}
\section{This kind of problem, that kind of problem, other ones and further considerations}
\section{More problems, even more problems, much worse than these, headline with no hyphenation and somo more text goes here for the example}

\end{document}

请参阅包装文档以进行进一步的调整。

答案2

我认为我倾向于使用 Gonzalo Medina 的答案,因为您正在使用scrreprt(并跳过加载tocloft),但tocloft解决方案并不太棘手(并且对memoir用户也很有用):

\documentclass{scrreprt}
\usepackage[ngerman]{babel}
\usepackage{tocloft}
\cftsetindents{section}{0mm}{12mm}
\cftsetindents{chapter}{0mm}{12mm}

\makeatletter
% \renewcommand{\@tocrmarg}{2.55em plus1fil}
\renewcommand{\@tocrmarg}{\@pnumwidth plus1fil} % <-- Revised
\makeatother

\begin{document}
\tableofcontents
\chapter{Introduction}
\section{This kind of problem, that kind of problem, other ones and further considerations}
\section{More problems, even more problems, much worse than these, headline hyphenation, and blablablablablablablablabla and XYZ-blablablablablablablablabla}

\end{document}

一般来说,您应该确保\@tocrmarg(TOC Right MARGin) 的修改值大于\@pnumwidth(Page NUMber WIDTH) 的修改值。

答案3

不建议将包与 KOMA-Script 类一起使用tocloft。以下是不使用这个包且不重新定义内部命令的建议:

\documentclass{scrreprt}
\RedeclareSectionCommands[
  tocindent=0mm,
  tocnumwidth=12mm,
  tocraggedentrytext
]{chapter,section}

\begin{document}
\tableofcontents
\chapter{Introduction}
\section{This kind of problem, that kind of problem, other ones and further considerations}
\section{More problems, even more problems, much worse than these, headline hyphenation, and blablablablablablablablabla and XYZ-blablablablablablablablabla}
\end{document}

结果:

在此处输入图片描述

您也可以使用类选项toc=flat来设置tocindent=0mmtocnumwidth=12mm

\documentclass[toc=flat]{scrreprt}
\RedeclareSectionCommands[
  tocraggedentrytext
]{chapter,section}

\begin{document}
\tableofcontents
\chapter{Introduction}
\section{This kind of problem, that kind of problem, other ones and further considerations}
\section{More problems, even more problems, much worse than these, headline hyphenation, and blablablablablablablablabla and XYZ-blablablablablablablablabla}
\end{document}

请注意,对齐需要额外运行一次。

结果:

在此处输入图片描述

答案4

使用以下软件包的解决方案titletoc

\documentclass{scrreprt}
\usepackage[showframe]{geometry}
%\usepackage[ngerman]{babel}
\usepackage{ragged2e}
\usepackage{fmtcount}
\usepackage{titletoc}
 \titlecontents{chapter}[12mm]
 {\contentsmargin{10mm}\bigskip\sffamily\bfseries\Large}
 {\contentslabel[\MakeUppercase{\romannumeral\thecontentslabel}]{12mm}}
 {}
 {\hfill\contentspage}[\medskip]


 \titlecontents{section}[12mm]
 { \rightskip=10mm plus 1fil\hyphenpenalty=10000\contentsmargin{2mm}}%
 {\contentslabel[\thecontentslabel.]{12mm}}
 {}
 {\hskip2pt\titlerule*[6pt]{.}\contentspage}


\begin{document}
\tableofcontents

\setcounter{page}{100}
\chapter{Introduction}
\section{This kind of problem, that kind of problem, other ones and further considerations}
\section{More problems, even more problems, much worse than these, headline hyphenation, and blablablablablablablablabla and XYZblablablablablablablablabla}

\end{document} 

在此处输入图片描述

相关内容