I am writing a LaTeX document with short sections which results in subsections being listed in the table of contents in the same or subsequent pages.

How can I suppress the appearance of page number for each subsection and make a list of subsections in a single sentence under their section? Some books use this style...

Edit: I am using the report document class and no special toc package

-

## migrated from stackoverflow.comJul 9 '12 at 15:28

This question came from our site for professional and enthusiast programmers.

Please also indicate which document class you're using (article, report, book, memoir, something else?) as well as if you're already loading any packages (such as tocloft) that affect the way the table of contents is organized. – Mico Jul 9 '12 at 17:45

The titletoc package provides a means to have "in-line" or paragraph-style ToC entries. You format a specific entry using

\titlecontents*{<section>}[<left>]
{<above code>}
{<numbered entry format>}
{<unnumbered entry format>}
{<filler page format>}
[<separator>][<end>]


The *-version of \titlecontents groups the entries in a single paragraph. Here's a minimal example highlighting its use, with the format settings taken from the titletoc documentation:

\documentclass[10pt]{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{titletoc}% http://ctan.org/pkg/titletoc
\titlecontents*{subsection}[1.5em]
{\small}
{\thecontentslabel. }
{}
{, \thecontentspage}
[.---][.]

\begin{document}
\tableofcontents

\section{First section}
\subsection{First}\subsection{Second}\subsection{Third}
\subsection{Fourth}\subsection{Fifth}\subsection{Sixth}
\subsection{Seventh}\subsection{Eighth}\subsection{Ninth}
\subsection{Tenth}

\section{Second section}
\subsection{First}\lipsum[2]\subsection{Second}\lipsum[2]
\subsection{Third}\lipsum[2]\subsection{Fourth}\lipsum[2]
\subsection{Fifth}\subsection{Sixth}\subsection{Seventh}
\subsection{Eighth}\subsection{Ninth}\subsection{Tenth}

\section{Last section}
\subsection{First}\lipsum[3]\subsection{Second}\lipsum[3]
\subsection{Third}\lipsum[3]\subsection{Fourth}\lipsum[3]
\subsection{Fifth}\subsection{Sixth}\subsection{Seventh}
\subsection{Eighth}\subsection{Ninth}\subsection{Tenth}

\end{document}


This prints the page number \thecontentspage with every \subsection entry, which is the default. It could be possible to extend this to include a page number for all \subsections on a page only once. However, this may require additional compilations and some forethought as to what the presentation should look like. For example, do you start with the "collective" page number, or do you end with it? If not handled properly, it my be confusing.

-