# Formatting TOC to ignore section and remove extra spaces

I want to format the TOC to ignore section and subsection since the chapters are all extremely small, and just list out the chapters without spaces between them.

but I don't understand how to use the styles at all.

How to use etocsetstyle to set the display of chapters, but turn off the display of all subsidiary levels? How to stop printing blank lines between chapters?

• Which document class are you using? You will certainly know that the “depth” at which sectioning commands show up in the table of contents is controlled by the tocdepth LaTeX counter. – GuM May 25 '15 at 13:43
• @GustavoMezzetti I am using document class book – Dov May 25 '15 at 15:53

The easiest way is to use tocloft:

\documentclass[a4paper]{book}
\usepackage[titles]{tocloft}

\setcounter{tocdepth}{0}
\setlength{\cftbeforechapskip}{0pt}

\begin{document}

\tableofcontents

\chapter{One}
\section{Aaaaa}
\section{Bbbbb}

\chapter{Two}
\section{Ccccc}
\section{Ddddd}
\section{Eeeee}

\chapter{Three}
\section{Fffff}
\section{Ggggg}
\section{Hhhhh}

\end{document}


You might want to avoid aligning the page numbers at the right margin, in this case; change the code above to

\documentclass[a4paper]{book}
\usepackage[titles]{tocloft}

\setcounter{tocdepth}{0}
\setlength{\cftbeforechapskip}{0pt}
\renewcommand\cftchapfillnum[1]{%
\nolinebreak\hspace{.5em}%
\textbullet
\nolinebreak\hspace{.5em}%
\textbf{#1}\cftparfillskip\par
}


to get

In your preamble, try the command \setcounter{tocdepth}{0}

Note that the answer to this question explains what number to use in the command argument if you want to change the depth displayed in the table of contents later.

• This does solve the 'problem' of hidding the sections, but not the chapter without spaces request ;-) – user31729 May 25 '15 at 14:44

The following is a “quick ‘n dirty” solution: see if it satisfies you.

\documentclass[a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage{lipsum}

\makeatletter
\renewcommand*\l@chapter{\@dottedtocline{0}{0em}{1.5em}}
\makeatother

\setcounter{tocdepth}{0} % Also try **without** this line.

\begin{document}

\tableofcontents

\chapter{One}
\lipsum[1]

\section{Aaaaa}
\lipsum[2]

\section{Bbbbb}
\lipsum[3]

\chapter{Two}
\lipsum[4]

\section{Ccccc}
\lipsum[5]

\section{Ddddd}
\lipsum[6]

\section{Eeeee}
\lipsum[7]

\chapter{Three}
\lipsum[8]

\section{Fffff}
\lipsum[9]

\section{Ggggg}
\lipsum[10]

\section{Hhhhh}
\lipsum[11]

\end{document}


Output: