# Grouping Together Sections in TOC

I am reviewing a series of documents and have created a report that looks like this:

\chapter{Interesting Things}
\input{thing1.tex}
\input{thing2.tex}
\input{thing3.tex}


where the thing*.tex each look like:

\section{The Name of The Thing}
\subsection{Summary}
A summary
\subsection{Details}
This contains details about the thing
\subsection{Conclusions}
My final analysis of the thing.


However, I have found that some things in my list are similar and I would like to group them together. I don't really care how the are numbered, but I would like the grouping to appear in the table of contents to organize them. For example, some of my things are circle and some square, so I would like to make a new level or grouping like this:

\chapter{Interesting Things}
\grouping{Square Things}
\input{thing1.tex}
\input{thing2.tex}
\grouping{Circle Things}
\input{thing3.tex}


I would like to avoid having to make changes to all the individual files. Is this possible?

• I have some idea for this but this depends on the packages used and the documentclass -- no such information is given by you :-( – user31729 Jan 10 '16 at 18:01

You could probably make things as complex as you want, but from a simplicity perspective, it seems sufficient to let \grouping{<something>} act in a very similar way to what a ToC-entry for \chapter*{<something>} would:

\documentclass{book}

% \grouping{<something>} acts similar to a ToC entry for \chapter*{<something>}

\begin{document}

\tableofcontents

\chapter{Interesting Things}

\grouping{Square Things}
\section{The Name of The Thing}
\subsection{Summary}
A summary
\subsection{Details}
This contains details about the thing
\subsection{Conclusions}
My final analysis of the thing.
\section{The Name of The Thing}
\subsection{Summary}
A summary
\subsection{Details}
This contains details about the thing
\subsection{Conclusions}
My final analysis of the thing.

\grouping{Circle Things}
\section{The Name of The Thing}
\subsection{Summary}
A summary
\subsection{Details}
This contains details about the thing
\subsection{Conclusions}
My final analysis of the thing.
\end{document}


Here's a solution with extra indentation and grouping:

Use \groupthings[some vertical spacing]{Foo} to write a chapter like group header to the ToC.

This automatically shifts the fake chapter heading and the section entries by a specified amount (tocloft is used here for simplify this.)

After a new real chapter starts, the old indentations must be restored, \RestoreIndents is called automatically when a new \chapter is used.

\documentclass{book}

\usepackage{tocloft}

\newlength{\extrachapindent}
\newlength{\extrasecindent}

\setlength{\extrachapindent}{10pt} % Indentation of chapters
\setlength{\extrasecindent}{20pt}  % Indentation of sections

% Store the old values
\newlength{\origchapindent}
\newlength{\origsecindent}
\setlength{\origchapindent}{\cftchapindent}
\setlength{\origsecindent}{\cftsecindent}

\newcommand{\RestoreIndents}{% Switch back to old values
}

\usepackage{xpatch}

\xpretocmd{\chapter}{\RestoreIndents}{}{}  % Automatically call \RestoreIndents before a new chapter is used

\newcommand{\groupthings}[2][2pt]{%
}

\begin{document}
\tableofcontents
\chapter{Some things}

\groupthings{Rectangular thingies}

\section{Rectangle things}
\section{Square things}

\groupthings{Round thingies}

\section{Circular things}
\subsection{Foo}
\subsubsection{Foobar}

\section{Oval things}

\RestoreIndents % Explicitly restore

\section{Something not being grouped}

\chapter{Other things}

\section{Triangular shapes}

\end{document}