2

I need a table of contents at the beginning of my appendix section. However, the following includes sections from the main text as well

\appendix
\tableofcontents

How can I get rid of those sections from the main text and just keep the ones from the appendix?

3

Background: It is quite logical that the table of contents is just created for the entire file, since every chapter/section/subsection/etc. are written to a .toc file and the \tableofcontents command just reads from that file (this is also thereason why you have to compile twice in order for the toc to be included correctly.

Now, to solve your question, you can use the minitoc package like this:

\documentclass[a4paper]{article}
\usepackage[toc,page,header]{appendix}
\usepackage{minitoc}

% Make the "Part I" text invisible
\renewcommand \thepart{}
\renewcommand \partname{}


\begin{document}
\doparttoc % Tell to minitoc to generate a toc for the parts
\faketableofcontents % Run a fake tableofcontents command for the partocs

\part{} % Start the document part
\parttoc % Insert the document TOC

\section{First}
First content.
\section{Second}
Second content.

\newpage
\appendix
\addcontentsline{toc}{section}{Appendix} % Add the appendix text to the document TOC
\part{Appendix} % Start the appendix part
\parttoc % Insert the appendix TOC

\section{Appendix First}
Appendix first content.
\section{Appendix Second}
Appendix second content.

\end{document}
  • Wow. Thanks. Worked great. One more thing: could you please tell me how to add subsections to the TOC. Now, it just includes sections. Can I also add something to TOC manually? – D_B Mar 9 '18 at 17:43
  • To add something manually, have a look at this: tex.stackexchange.com/questions/119719/… And for the toc depth (so the chapter-section-subsection-etc) see: tex.stackexchange.com/a/17879/114249 – Foitn Mar 9 '18 at 20:45

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.