How do I suppress pagebreaks in the toc "paragraphs" produced by titlesec's \titlecontents* command without stopping linebreaks between subsections?

The follwoing suppresses linebreaks within subsection, but doesn't deal with pagebreaks. titlesec does internally use \nobreak and \addpenalty in the definition of \ttl@outnoblock, but I don't know where I would have to add them.

  {\thecontentslabel.\nobreakspace\mbox}{\mbox}{,\nobreakspace\thecontentspage}[][ -- ][.]







\chapter{my first chapter}\label{ch:first}
\section{my first section}\label{sec:first}
\addtocontents{toc}{\vspace{11cm}} %for the example
\chapter{my second chapter}
\section{my second section}\label{sec:second}
\subsection{first subsection}
\subsection{second subsection}
\subsection{third subsection}
\subsection{4th subsection}
\subsection{5th subsection}
\subsection{6th subsection}
\subsection{7th subsection}


It might in general be better just to increase the penalty than absolutely forbid the pagebreak, but in my particular case forbidding it might be sufficient.

The pagebreak functionalities of titletoc should be retained if possible:

Pages are never broken between entries if the first one is of an higher level than the second one as, for instance, between a section and a subsection. If both of them are of the same level, the break is allowed, and if the first is lower than the second, it is considered a good place for a page break.


I don't know if this is completely foolproof, but it seems to work with your example:


  {,\nobreakspace\thecontentspage}[][ -- ][.]

With \filbreak we roughly say to break unless what comes before the following \filbreak can stay in the page.

For the first section after a chapter we mustn't issue the \filbreak: here's a sketch, one needs probably to redefine the chapter entries.



  {,\nobreakspace\thecontentspage}[][ -- ][.]
  • When I introduce a chapter before this section the pagebreak will occur between chapter and section, which normally titletoc forbidds. Can u improve your answer to restore this benefit (see my edited question)? – Markus Schmassmann May 16 '12 at 16:30
  • \filbreak seems to introduce an additional newline, adding \vspace{-\baselineskip} before each \filbreak gets the vertical spacing correct. Is there something less hacked? – Markus Schmassmann May 16 '12 at 17:58

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.