[Tex/LaTex] Line break in section name

line-breakingsectioning

Is there any easy way to force a line break in a section name manually, without getting the line break in the Table of Contents? It's because I have a rather long section name, and it breaks just only the last three letters and it looks stupid, but there is no problem in ToC. I have tried double-\ but it breaks the line in the ToC as well.

I have looked at How to put a line-break in section heading? and tried

\texorpdfstring

And it does break the line, but the new line starts below the section number, not below the section name.

(I'm using PDFLaTeX for compiling in TexMaker, and I would prefer not to change that.)

Another solution could be to squeeze the title a bit, if that is possible? I don't think it would be noticeable.

Best Answer

You can use the optional argument for the section (inside [...]) which will used for running content:

\documentclass{article}
\usepackage{lipsum}

\begin{document}
\tableofcontents

\section[my section]{This is going to \\ go for two lines}
\lipsum

\end{document}

enter image description here

Make sure to use a short title in the optional argument.