I have a very long section title which has no spaces in it. This seems to cause problems with wrapping the title in the table of content and in the header (it doesn't work). I'm also having the same problem with long lines with no spaces using the minted package.

Is there a generic fix for this?

Here is an example (also at https://www.overleaf.com/read/qyvwgrnhpbfm):



\expandafter\def\csname PYGdefault@tok@err\endcsname{\def\PYGdefault@bc##1{{\strut ##1}}}






  • Welcome to TeX.SX! Is this a real situation or just a curiosity? Add \hspace{0pt} in front of the title, like \section{\hspace{0pt]LONG}. For minted, there's an option to break lines anywhere. – egreg Mar 21 '18 at 14:24
  • There is also \allowbreak which can be inserted in specific sites. – John Kormylo Mar 21 '18 at 15:12
  • Hi @egreg. This is a real situation. I'm adapting this answer and have some very long file paths (some without spaces) which need wrapping in the table of content. I tried \hspace{0pt} and got this result. – user158752 Mar 21 '18 at 15:42

Actually, this seems like two questions:

In section headings, you can use \- to allow \LaTeX to hyphenate there:


This also hyphenates in the Table of Contents (not necessarily at the same position).

For the minted package you can use the breakanywhere option (which egreg mentions in his comment):


Output: Output with the modifications

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy