# Contextual newlines in tocloft

I'm using a shorttoc with tocloft to put the names of chapters on a newline. Unfortunately, there are some chapters (such as the Preface or Index) which are not numbered, and I end up with additional, ugly, newlines between them:

Here is a MWE of my problem:

\documentclass{scrbook}

\usepackage[english]{babel}
\usepackage{shorttoc}

\usepackage{tocloft}
\renewcommand\cftchappresnum{Chapter\ }
\renewcommand\cftchapaftersnumb{\newline} % This is the newline I'd like to be contextual

\usepackage{blindtext}

\begin{document}

\shorttableofcontents{Contents}{0}

\blindtext

\Blinddocument

\blindtext

\tableofcontents

\end{document}


and the result is:

How could I keep the newlines for numbered chapters and get rid of it for entries that are not numbered?

Edit:

Actually, I'm realizing that what I'm trying to achieve is to reduce the interline between the chapter entries in the toc. How can I do that?

-
Personally, I think the ToC looks better with the extra spacing. IMHO, the only thing that needs changing is adding extra space above the index heading. Then all ‘normal’ chapters would be seen as one block, and ‘special’ chapters would be separate blocks. –  Karl Ove Hufthammer Nov 14 '11 at 10:41

Instead of \newline use your own macro, redefined by each chapter head to give a newline and then empty itself (hence to only produce one newline for each chapter head). When the Chapter\ head is not used, the newline won't either.

\newcommand{\newlineornot}{}
\renewcommand\cftchappresnum{Chapter\ \gdef\newlineornot{\newline\gdef\newlineornot{}}}
\renewcommand\cftchapaftersnumb{\newlineornot}


Or, in a full document,

\documentclass{scrbook}

\usepackage[english]{babel}
\usepackage{shorttoc}

\usepackage{tocloft}
\newcommand{\newlineornot}{}
\renewcommand\cftchappresnum{Chapter\ \gdef\newlineornot{\newline\gdef\newlineornot{}}}
\renewcommand\cftchapaftersnumb{\newlineornot}

\usepackage{blindtext}

\begin{document}

\shorttableofcontents{Contents}{0}

\blindtext

\Blinddocument

\Blinddocument

\blindtext

\tableofcontents

\end{document}

-
Thanks for the suggestion, but that doesn't fix my issue. –  ℝaphink Aug 10 '11 at 5:54
@Raphnik: ah, yes, actually I should have realized that the output still had the same spaces. –  Bruno Le Floch Aug 10 '11 at 15:32

It turns out that the problem was the spacing between chapter entries in the toc.

This simple setting did the job:

\setlength{\cftbeforechapskip}{-0.3em}


So I end up with something like:

\setlength{\cftbeforechapskip}{-0.3em}
\renewcommand\cftchappresnum{Chapter\ }
\renewcommand\cftchapaftersnumb{\newline}