請不要在目錄條目中使用連字符

請不要在目錄條目中使用連字符

我有一些很長的章節標題,並且不希望目錄中的條目用連字符連接。 範例輸出

\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},「consid-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

tocloft不建議將套件與 KOMA-Script 類別一起使用。這是沒有這個套件並且沒有重新定義內部命令的建議:

\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} 

在此輸入影像描述

相關內容