# 2nd column in TOC with subtitles for subsection and subsubsection

The sections should look like this in the main document:

Important Features of the TOC:

1. Subsections can have TITLES (smallcaps), Subtitles (normal) and extra information (italics) that are formatted differently. (But note that they don't have to have all three of these, some Subsections might just have a title, or just a subtitle and information, etc.)
2. Subtitles are right-aligned while everything else is left-aligned and the gap is filled with dots.
3. (Ideally) multi-line titles and subtitles are handled gracefully.

Section style in main document:

1. Subsections have different formatting for TITLES (smallcaps), Subtitles (normal) and extra information (italics).
2. Subtitles are right-aligned while everything else is left-aligned and the gap is filled with dots.
3. (Ideally) multi-line titles and subtitles are handled gracefully.

Here's the code I used to fake the above images (with a little help from GIMP). Obviously I'd like a better solution than manually adding dots to get the right spacing.

\documentclass[a4paper]{article}
\usepackage{bold-extra} % Allows simultaneous bold and small-caps

\begin{document}
\tableofcontents

\section{Introduction}
My primary concern is the Table of Contents, but ideally section headings in the main part of the document should follow a similar style, with the correct formatting for \textsc{Section Titles} and \textit{(Extra Information)}, and Subtitles appearing on a separate line beneath the main titles.

The first part of this code (almost) creates a correctly formatted Table of Contents, but the formatting is wrong in the main document. The second part of the code shows how the formatting should look in the main document.

\section{First Section}
\subsection{\textsc{First Subsection} \textit{(extra info)} . . . . . . . . . . . . . . . Subtitle}
Normal text. This subsection has a title, subtitle and extra information.

\subsection{\textsc{Second Subsection} . . . . . . . . . This subtitle is so long that \\it takes 2 lines in the TOC}
This subsection lacks any extra information.

\subsubsection{\textsc{First Subsubsection} \textit{(extra info)} . . . . . . . . Subtitle}
Some Subsections have Subsubsections. These can have titles, subtitles and extra infomation too.

\subsection{\textit{(Information)} . . . . . . . . . . . . . . . . . . . . . . . . . . . Subtitle}
This subsection lacks a title.\\[1cm]
{\Large\bfseries{1 \hspace{2mm} First Section}}\\[3mm]
{\large\bfseries{\textsc{1.1 \hspace{2mm} First Subsection} \textit{(extra information)}}}\\[2mm]
\indent \hspace{4.5mm} \textit{\large Subtitle}\\[3mm]
Normal text. This subsection has a title, subtitle and extra information.

\end{document}


Please include a screenshot of the output PDF with your answer.

note: the code below has forgotten the

\usepackage{bold-extra} % Allows simultaneous bold and small-caps


line, hence the subsection headings in the main document are not in small caps. Just add the line to the code. (image not updated)

To obtain this one must do some surgery on the way LaTeX handles subsections in the TOC. The main thing one needs to do is to remove the dots put by default before the page number and insert some dots at another location. I hesitated between

1. pacth directly \l@subsection,
2. go with tocloft,
3. go with etoc.

Option 1 would mean repeating the hard-coded lengths as in the LaTeX kernel source, which is not optimal. Unfortunately the question gives no indication about the class used, an information which is crucial if the answerer is not to return 5 times to modify his/her answer according to additional extra datas given piece by piece by the OP.

Option 2 allows some more conceptual approach, but does require some tricks because as the structure is not entirely customizable: in the case at hand the strange \\[-\baselineskip]\null one sees in the code are a trick to handle some horizontal glue one can not otherwise remove (there is also a \strut to handle another issue).

Option 3 would have allowed a code with no tricks (for example no need to define a boolean and put the TOC in an environment to inform our macros where they expand, no need for a \\[-\baselineskip]\null, no need for an unusual 1\filll), but again as we would have been in complete control we would have needed to know the class which would have told us what we were supposed to emulate.

The user should use \HFCtitle, \HFCinfo, \HFCsubtitle as in the example for mark-up of the subsection title data. Leave a space after the \HFCtitle and before the \HFCinfo.

The dots ending the subtitles in the TOC will not necessarily be aligned with dots after the titles from other entries, but they should be aligned with the dots after other subtitles. To achieve perfect alignement is another matter for which I would go with option 3 (etoc) to benefit from complete control from the start.

\documentclass{article}

\usepackage{tocloft}
\renewcommand\cftsubsecdotsep{\cftnodots}

\makeatletter
\newif\ifHCFintoc
\newbox\HCFbox
% subsection titles in toc as in document
\protected\def\HCFtitle #1{\textsc{#1}}
% subsection infos in toc as in document
\protected\def\HCFinfo  #1{\emph{(#1)}}
% subsection subtitles need special formatting in toc
%
\protected\def\HCFsubtitle #1%
{%
\ifHCFintoc
%
\allowbreak\null\nobreak
\leaders\hbox{$\m@th\mkern \cftdotsep mu\hbox{\cftdot}\mkern \cftdotsep mu$}%
\hskip\z@ \@plus \@ne filll
%
\setbox\HCFbox\hbox{#1}%
\ifdim\wd\HCFbox>.3\columnwidth
\parbox[t]{.3\columnwidth}{#1%
\hbox{$\m@th\mkern \cftdotsep mu\hbox{\cftdot}\mkern \cftdotsep mu$}%
\hskip\z@ \@plus \@ne filll \strut}%
\else
#1%
\fi
\\[-\baselineskip]\null
\else
\\\textnormal{#1}%
\fi
}%
\makeatother
\newenvironment{HCFintoc}{\HCFintoctrue}{}

\begin{document}

\begin{HCFintoc}
\tableofcontents
\end{HCFintoc}

\section{First section}

\subsection{\HCFtitle{First subsection}
\HCFinfo{some info}\HCFsubtitle{This is a very very very very very
very very long subtitle}}
Hello

\subsection{\HCFtitle{Second subsection}
\HCFinfo{some info}\HCFsubtitle{This is a subtitle}}
Hello

\subsection{\HCFtitle{Third subsection}
\HCFinfo{some info}\HCFsubtitle{This is a very very very very very
very very long subtitle}}
Hello

\section{Second section with a v e r y v e r y v e r y v e r y v e r y
v e r y v e r y v e r y v e r y v e r y
v e r y v e r y long title}

\subsection{\HCFtitle{First subsection with a v e r y v e r y v e r y v e r y v e r y
v e r y v e r y long title}
\HCFinfo{some info}\HCFsubtitle{This is a very very very very very
very very long subtitle}}
Hello

\subsection{\HCFtitle{Second subsection with a v e r y v e r y v e r y v e r y v e r y
v e r y v e r y long title}
\HCFinfo{some very very very very very
very very long info}\HCFsubtitle{This is a very very very very very
very very long subtitle}}
Hello

\end{document}


The page 1:

• Thanks! I'm afraid I don't understand what you mean by "class" in your explanation of Option 1. I included the document class (article), but do you mean something else? Dec 28 '15 at 20:53
• In the TOC, is there an easy way to remove the dots after the subtitles (RHS) but keep the dots in the middle of the page? Dec 28 '15 at 20:53
• @HullCityFan852 in the \protected\def\HCFsubtitle, locate the three lines after \parbox[t]{.3\columnwidth}{#1%, and delete or comment them out (the first line has a single \leaders and the third one is \cftdotsep mu\$}%)
– user4686
Dec 31 '15 at 8:42