2

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?

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

2 Answers 2

1

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:

enter image description here

\documentclass{book}

% \grouping{<something>} acts similar to a ToC entry for \chapter*{<something>}
\newcommand{\grouping}[1]{\addcontentsline{toc}{chapter}{\protect\numberline{}#1}}

\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}
2

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
  \addtocontents{toc}{\protect\setlength{\cftchapindent}{\origchapindent}}%
  \addtocontents{toc}{\protect\setlength{\cftsecindent}{\origsecindent}}%  
}




\usepackage{xpatch}


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

\newcommand{\groupthings}[2][2pt]{%
  \addtocontents{toc}{\protect\addvspace{#1}}%  Vertical spacing
  \addtocontents{toc}{\protect\setlength{\cftchapindent}{\extrachapindent}}% indent the chapters
  \addtocontents{toc}{\protect\contentsline{chapter}{#2}{}}% Write the text
  \addtocontents{toc}{\protect\addvspace{#1}}% Other vertical spacing
  \addtocontents{toc}{\protect\setlength{\cftsecindent}{\extrasecindent}}% Indent the chapters
}




\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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .