Page LayoutLine Break in Section Heading without Hyphenation

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
zidangus
Posts: 4
Joined: Sun Apr 01, 2012 10:24 pm

Line Break in Section Heading without Hyphenation

Post by zidangus »

Ok so I have a long section heading that has two lines, however I do not like the words being broken with a hyphen, so I inserted a line break to make it look nicer on the eye. Anyway it works fine when compiling except for the ToC, where there is not no space between the word before the line break and the word after the line break. Can anyone help to rectify this, so that ToC look ok.

What I have done

Code: Select all

\subsection{This is the first line of the heading \\ and this is the second}
When compiled looks like this

Code: Select all

This is the first line of the heading
and this is the second
However TOC looks like this

Code: Select all

This is the first line of the headingand this is the second
any :idea:

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Line Break in Section Heading without Hyphenation

Post by Stefan Kottwitz »

Hi,

sectioning commands have an optional argument which would be used for the table of contents, if specified. See Sectioning in the LaTeX manual. So you could write

Code: Select all

\subsection[This is the first line of the heading and this
  is the second]{This is the first line of the heading \\ and this is the second}
or use \mbox{...} to prevent hyphenation of a word.

Stefan
LaTeX.org admin
zidangus
Posts: 4
Joined: Sun Apr 01, 2012 10:24 pm

Re: Line Break in Section Heading without Hyphenation

Post by zidangus »

Thanks very much Stefan_K, it works a treat, appreciate it ! :D
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Line Break in Section Heading without Hyphenation

Post by localghost »

You can format all heading levels accordingly by using the titlesec package.

Code: Select all

\usepackage[raggedright]{titlesec}
Now you don't have to bother any more about optional arguments and correctly formatted ToC entries.

In the classes of the KOMA-Script bundle this kind of formatting is the default setting.


Best regards and welcome to the board
Thorsten
Post Reply