3

I want the label and title of subsection typsetting as a paragraph but NEVER break down in a subsection title. Say, the code below

\documentclass{article}
\usepackage{titletoc}

\titlecontents*
{subsection}
{}
{\thecontentslabel:\nobreakspace}{}
{\nobreakspace(\thepage)}[.\quad]

\begin{document}
\tableofcontents



\section{A section}
\subsection{A subsection}
\subsection{Another subsection}
\subsection{A very long subsection}
\subsection{Again a subsection}
\subsection{A longest subsection in the article!}

\end{document}

I want the label of subsection 1.3 and 1.5 start in a new line respectively, like

1.1: A subsection (1)   1.2: Another subsection (1)
1.3: A very long subsection (1)   1.4: Again a subsection (1)
1.5: A longest subsection in the article! (1).
Michael Ummels
  • 8,604
  • 3
  • 36
  • 27

1 Answers1

3

You can put the whole label into a box by adding \mbox to the label argument of \titlecontents. Also, I guess that you want to set the relevant parts of the TOC ragged-right to avoid labels running into the margin.

\titlecontents*%
{subsection}%
{\raggedright}%
{\thecontentslabel:\nobreakspace\mbox}{\mbox}%
{\nobreakspace(\thepage)}[.\quad]
Michael Ummels
  • 8,604
  • 3
  • 36
  • 27