4

This question is almost a repeat of previous one : How do I get multiple ToC entries in the same line?. However, I need an answer using tocloft, not titletoc, since tocloft customization capabilities are better in my views that titletoc ones. Do you thing it is feasible with tocloft?

EDIT: Here is what I would like to get, the subsubsection in the book class are on the same line, with no numbering but with page numbers:

enter image description here

Martigan
  • 3,146

1 Answers1

5

Here's one possible solution, using a variation of the technique used in this answer to How to emulate titletoc with tocloft:

\documentclass{book}
\usepackage{etoolbox}

\newlength\rightmargintoc
\setlength\rightmargintoc{\linewidth}
\addtolength\rightmargintoc{-3em}

\makeatletter
\def\subsubsectocline#1#2#3#4#5{%
\parshape 2  0em \rightmargintoc \dimexpr\parindent\relax \rightmargintoc
\@tempdima#3
\ifdim\lastskip=1sp\relax\ \else\par\fi{\small\itshape#4,~p.#5.}\hskip1sp%
}
\renewcommand*\l@subsubsection{\subsubsectocline{2}{0em}{3em}}
\makeatother

\pretocmd{\part}{\addtocontents{toc}{\par}}{}{}
\pretocmd{\chapter}{\addtocontents{toc}{\par}}{}{}
\pretocmd{\section}{\addtocontents{toc}{\par}}{}{}
\pretocmd{\subsection}{\addtocontents{toc}{\par}}{}{}

\AtEndDocument{\addtocontents{toc}{\par}}

\begin{document}
\addtocontents{toc}{\setcounter{secnumdepth}{2}}
\tableofcontents

\part{Test Part One}
\chapter{Test Chapter}
\section{Test Section One}
\subsection{Test Subsection One One}
\subsubsection{First Test Subsubsection}
\subsubsection{Second Test Subsubsection}
\subsubsection{Third Test Subsubsection}
\newpage
\subsubsection{Fourth Test Subsubsection}
\subsection{Test Subsection One Two}
\subsubsection{First Test Subsubsection}
\subsubsection{Second Test Subsubsection}
\subsubsection{Third Test Subsubsection}
\part{Test Part One}
\chapter{Test Chapter}
\section{Test Section One}

\end{document}

The resulting ToC:

enter image description here

Gonzalo Medina
  • 505,128
  • Thank you very much, it is working great. I don't know why I did not succeed in adaptating your previous answer... There remains an issue, in the book class, with the parts in the toc. the part toc entry starts right after the last subsubsection item. Do you know why? I can add a phantom section and try to reduce vertical space, but it is quite ugly. @GonzaloMedina – Martigan Nov 17 '12 at 13:37
  • @Martigan there was a problem with my code that now I've fixed. Please try the improved version (delete the auxiliary files first) of my updated answer. – Gonzalo Medina Nov 17 '12 at 13:53
  • Thanks a lot. It is now working perfectly. @GonzaloMedina – Martigan Nov 17 '12 at 14:19