Page LayoutLong Section Title in Table of Contents

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
bkarpuz
Posts: 124
Joined: Thu Dec 18, 2008 4:53 pm

Long Section Title in Table of Contents

Post by bkarpuz »

Dear friends,

how can I divide a section title into two lines if the title is very long.
please see the code below.

Code: Select all

\tableofcontents

\section*{\centering MyLongSectionTitleNeedsToBeSplittedIntoTwoLines}
\addcontentsline{toc}{section}{MyLongSectionTitleNeedsToBeSplittedIntoTwoLines}
thanks.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

Long Section Title in Table of Contents

Post by kaiserkarl13 »

This looks like a job for optional hyphens:

Code: Select all

\tableofcontents

\section*{\centering My\-Really\-Really\-Really\-Really\-Long\-Section\-Title\-Needs\-To\-Be\-Splitted\-Into\-Two\-Lines}
\addcontentsline{toc}{section}{My\-Really\-Really\-Really\-Really\-Long\-Sectio-Title\-Needs\-To\-Be\-Splitted\-Into\-Two\-Lines}
Incidentally, it's only having trouble because you have no spaces in the word. If you give it a title with spaces, TeX will break the lines automatically.
bkarpuz
Posts: 124
Joined: Thu Dec 18, 2008 4:53 pm

Long Section Title in Table of Contents

Post by bkarpuz »

kaiserkarl13 wrote:This looks like a job for optional hyphens:

Code: Select all

\tableofcontents

\section*{\centering My\-Really\-Really\-Really\-Really\-Long\-Section\-Title\-Needs\-To\-Be\-Splitted\-Into\-Two\-Lines}
\addcontentsline{toc}{section}{My\-Really\-Really\-Really\-Really\-Long\-Sectio-Title\-Needs\-To\-Be\-Splitted\-Into\-Two\-Lines}
Incidentally, it's only having trouble because you have no spaces in the word. If you give it a title with spaces, TeX will break the lines automatically.
Thanks it worked.
Post Reply