## LaTeX forum ⇒ Page Layout ⇒ Problem with table of contents Topic is solved

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
ciema7
Posts: 16
Joined: Sat Nov 10, 2018 2:31 am

Hello,

I have some problems with my ToC. Is there a simply way to align better long sections names ? I add photo, which ilustrates my problem (section 2).
Attachments
question.png (26.77 KiB) Viewed 399 times

Johannes_B
Site Moderator
Posts: 4044
Joined: Thu Nov 01, 2012 4:08 pm
This completely depends on the class you are using and maybe packages used to customize chapter headings. Can you show a minimal working example?
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

ciema7
Posts: 16
Joined: Sat Nov 10, 2018 2:31 am
Thanks for reply! I present my code below (it is long because its my master thesis code, maybe the problem is with these 4 rows started with \tolerance=1 ?):

Last edited by Stefan Kottwitz on Wed May 08, 2019 4:15 pm, edited 1 time in total.
Reason: code marked

Stefan Kottwitz
Posts: 9405
Joined: Mon Mar 10, 2008 9:44 pm
Hello,

that centering here causes it:

\begin{centering}\tableofcontents\end{centering}

Just change to
\tableofcontents

and test again. Compile two times to update the table of contents.

I guess all your section headings are left aligned. In that case I would be consistent and let the contents (section) heading left aligned too. If you really would like to have this single heading of the contents to be centered, let us know, there would be a different way.

Stefan

ciema7
Posts: 16
Joined: Sat Nov 10, 2018 2:31 am
Thank you very much, it works, but here is my another question . Is there any simple way to not divide my last word in the any row in table of contest and not to throwing the part of the word to the next row (below), but whole this (divided) word throw to the next row?

PS. Stefan you can edit your previous post and delete this " } " from the second code, you provided Just formality. Thanks again for help!!!

Stefan Kottwitz
Posts: 9405
Joined: Mon Mar 10, 2008 9:44 pm
Here is a way:

\usepackage{tocstyle}\usetocstyle{standard}\settocfeature{raggedhook}{\raggedright}

Stefan

Ijon Tichy
Posts: 34
Joined: Mon Dec 24, 2018 10:12 am
Usage of tocstyle is deprecated and not recommended. But you can get a similar result using:

\usepackage{tocbasic}% One more KOMA-Script package added.% Using tocbasic to make the table of contents:\renewcommand*{\tableofcontents}{\listoftoc[\contentsname]{toc}}\DeclareTOCStyleEntries[raggedentrytext]{tocline}{section,subsection,subsubsection,paragraph,subparagraph}

Here added to the original code. Please have a look to my additional comments in this code:

BTW: A more minimal but working example for the problem would be:
\documentclass[12pt]{article}% fontsize=12pt is a KOMA-Script option. To have                             % the same with article you need to use 12pt.\usepackage{mwe}% useful for minimal but working examples \usepackage{tocbasic}% One more KOMA-Script package added. \usepackage{hyperref}% Must be loaded after float!!!!                     % Generally you should load hyperref after all other                     % packages but those for which the manual of either the                     % package or hyperref tells you, that you should load it                     % after hyperref.\usepackage{bookmark}% It is recommended to use this with hyperref, because it                     % improves generation of bookmarks. % Using tocbasic to make the table of contents:\renewcommand*{\tableofcontents}{\listoftoc[\contentsname]{toc}}\DeclareTOCStyleEntries[raggedentrytext]{tocline}{section,subsection,subsubsection,paragraph,subparagraph} \begin{document} \tableofcontents \section[Introduction in the table of contents, where even this verylongtext-entry  is raggedright using \textsf{tocbasic}]{Introduction} \lipsum[1] % provided by package lipsum loaded by package mwe (which you are           % already using to get dummy text) \end{document}

or using KOMA-Script class scrartcl:
\documentclass[fonsize=12pt]{scrartcl}\usepackage{mwe}% useful for minimal but working examples \usepackage{hyperref}% Must be loaded after float!!!!                     % Generally you should load hyperref after all other                     % packages but those for which the manual of either the                     % package or hyperref tells you, that you should load it                     % after hyperref.\usepackage{bookmark}% It is recommended to use this with hyperref, because it                     % improves generation of bookmarks. % Make the text of all ToC entries ragged-right\DeclareTOCStyleEntries[raggedentrytext]{tocline}{section,subsection,subsubsection,paragraph,subparagraph} \begin{document} \tableofcontents \section[Introduction in the table of contents, where even all these strange  verylongtextentry are raggedright using \textsf{tocbasic}]{Introduction} \lipsum[1] % provided by package lipsum loaded by package mwe (which you are           % already using to get dummy text) \end{document}