
У меня есть несколько очень длинных заголовков разделов, и я не хочу, чтобы их записи в оглавлении были разделены дефисами.
\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}
, дефис «conside-erations» меняется на «conside-derations», что интересно.)
Проблема возникает также, когда я не использую tocloft
или меняю класс документа на book
, например (с переносами на разных слогах).
Могу ли я полностью убрать переносы в TOC, не прибегая к их переопределению для каждого неправильного слова?! Бонусные баллы, если решение не заставит длинные слова выноситься за пределы строки, как, например, последнее «блабла...», еще больше бонусных баллов, если словосочетания, которые начинаются с дефиса («XYZ-блабла»), можно будет перенести на одну строку.
решение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
Думаю, я был бы склонен использовать ответ Гонсало Медины, учитывая, что вы используете 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}
Результат:
Вы также можете использовать опцию class toc=flat
вместо setting tocindent=0mm
и tocnumwidth=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}