I have several section titles in my document that are getting hyphenated, which is quite ugly.
I am now looking for some way to avoid the hyphenation, which is is somewhat related to this question, but unfortunately my titles have to be centered (so raggedright
is not an option), and adding \sloppy
to my titlesec
definition of the subsection format didn't help:
\newcommand{\trailthesubsection}[1]{\MakeUppercase{#1} (\thesubsection)}
\titleformat{\subsection}
{\normalfont\fontsize{15pt}{16pt}\bfseries\sffamily\sloppy} % <- "sloppy" didn't help.
{}
{0pt}
{\filcenter\trailthesubsection}
I could, of course, set manual linebreaks – but in order not to destroy the layout of my TOC in the process, I would have to use the optional parameter to the section commands:
\subsection[Could do this but it is not nice]{Could do this\\ but it is not nice}
Isn't there some way to suppress hyphenation for a given text (e.g. by some command in the \titleformat
), or to suppress manually-set linebreaks in the TOC?
Best Answer
See this question in the UK TeX FAQ for a discussion of four different methods for turning off hyphenation. Method three and four consist of adding the instructions
and
respectively. The latter approach is used in the following MWE:
Note that the
\sloppy
command will prevent TeX from creating (seriously!) overfull lines in the section title.Note (thanks to egreg): the
\hyphenchar\font-1
instruction is global, so all other text in the document set in\bfseries\Large
will also see hyphenation suppressed -- which may (or may not) be what's desired. Therefore, the\righthyphenmin62
method may be marginally safer to use (pun intended). However, according the UK TeX FAQ's answer noted earlier, if you're ababel
user the method of resetting the \left- and/or \righthyphenmin macros won't work asbabel
resets them internally.Addendum: To prevent hyphenation in the optional shortened section title (to be displayed in the table of contents), one would have to insert the instructions
at the start of the material in the optional argument of the
\section
command. (My feeling is that if a section caption is longer than one line, it's probably wise to provide a shortened caption that's short enough not to need a line break at all.)