0

I have a main document which contains a secondary documents table of contents. I'm using the example given in the first half of this answer.

My secondary ToC doesn't use section numbering. I assume this is because I haven't defined the necessary bits for toca, but I'm not sure what those bits are.

How can I enable section numbering for my secondary table of contents?

Here's a minimal, working example:

\documentclass{report}
\usepackage{tocloft}
\makeatletter
\newcommand\tableofcontentsA{%
    \@starttoc{toca}%
}
\makeatother

\begin{document}
\tableofcontents

\section{Main introduction}
\section{Example Document-2 Table of Contents}
% These are all defined in the same page, so disable page numbering    \cftpagenumbersoff{chapter}
\cftpagenumbersoff{section}
\cftpagenumbersoff{subsection}

\addcontentsline{toca}{chapter}{Introduction}
    \addcontentsline{toca}{section}{foo}
    \addcontentsline{toca}{section}{bar}
\addcontentsline{toca}{chapter}{baz}
    \addcontentsline{toca}{section}{barbar}

\tableofcontentsA
\section{Main Conclusion}

\end{document}

Here's what it produces:

Example document

I'd like to have something more like this:

1 - Main intro
2 - Example ToC
    1 - Intro
    1.1 - foo
    1.2 - bar
    2 - Baz
    2.1 - barbar
3 - Main Conclusion
0

Here is how I would go for it:

\documentclass{report}
\usepackage{tocloft}

\makeatletter
\newcommand\tableofcontentsA{%
\indent
    \@starttoc{toca}%
}
\makeatother

\newcounter{tocachap}
\setcounter{tocachap}{0}

\newcounter{tocasect}[tocachap]
\setcounter{tocasect}{0}
\renewcommand{\thetocasect}{\thetocachap.\arabic{tocasect}}

\newcommand{\addchap}[1]{\refstepcounter{tocachap}
\cftaddtitleline{toca}{tocachap}{\indent\textbf{\thetocachap \hspace{1em}#1 \\[0.2em]}}{}
\par}

\newcommand{\addsect}[1]{\refstepcounter{tocasect}
\cftaddtitleline{toca}{tocasect}{\indent\thetocasect \hspace{0.5em}#1 \\[0.2em]}{}
\par}

\renewcommand{\thesection}{\arabic{section}}

\begin{document}
\tableofcontents

\section{Main introduction}
\section{Example Document-2 Table of Contents}

\addchap{Introduction}
\addsect{foo}
\addsect{bar}
\addchap{baz}
\addsect{barbar}

\tableofcontentsA
\section{Main Conclusion}

\end{document}

It produces this output:

Output

Note 1 It is possible to create a command for the subsections.

Note 2 Due to the redefinition of the section counter you should not use any chapter in your document because it may create a confusing main table of contents.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.