# Remove section/subsection from one of two TOC

I have two TOC in my document, one for the hole document ("main" TOC) and one for only the appendix. I want to remove all sections and subsections from appendix in the "main" TOC but not in the TOC for appendix. Is this possible without re-coding everything. I have tied using:

\newcommand{\nocontentsline}[3]{}


with

\tocless\section{section name}


But with this i lose the subsection in the smaller TOC for the appendix. I have tried different placement of the command above but that does't work.

This is the code I have now that generate my two TOC:

\usepackage{titletoc}

\documentclass[a4paper, 12pt]{book}

\begin{document}

%first TOC at beginning of document:

\tableofcontents

%Second TOC just before Appendix for the Appendix:

\startcontents
\renewcommand{\contentsname}{Appendix}
\printcontents{}{0}{%
\setcounter{tocdepth}{2}%
\tableofcontents}


Anybody know how to solve this? J

• Why not use the starred version of section* subsection* in the documents appendix, which does not give a TOC entry? – Bernhard Kleine May 19 '16 at 14:15
• This does not solve my problem what i can see. If i use section* and subsection* these disappears from both TOC's. I want them to remain in the TOC for the appendix but not in the main TOC... – mwasberg May 19 '16 at 14:24
• Have you ever used the minitoc package? there are different tocdepth versus minitocdepth possible. – Bernhard Kleine May 19 '16 at 14:38
• See the manual, sec. 4.2. – Javier Bezos May 19 '16 at 14:42

Here is a solution.

Use

\addcontentsline{toc}{chapter}{Appendix}


Update because of expansion (issue with calc package see comments) it's better to use

\addcontentsline{toc}{chapter}{Appendix}


\documentclass[a4paper, 12pt]{book}
\usepackage{titletoc}
\usepackage{blindtext}
\begin{document}
\tableofcontents
\blinddocument
\blinddocument

%Second TOC just before Appendix for the Appendix:
\cleardoublepage
\appendix
\startcontents
\renewcommand{\contentsname}{Appendix}
\printcontents{}{0}{%
\setcounter{tocdepth}{2}%
\tableofcontents}
\blinddocument
\blinddocument

\end{document}


main toc

Appendix toc

• Big thanks for this, but i cant get it to work as above. When using: \addtocontents{toc}{\setcounter{tocdepth}{0}} and \addtocontents{ptc}{\setcounter{tocdepth}{2}} i get warnings. If i skip the TOC for the appendix part and only use \addtocontents{toc}{\setcounter{tocdepth}{0}} just after \appendix i still get warnings. Is there a usepackage i'm missing, because after this command logical this should work and only show appendix heading on level 0 (chapter?) in the main TOC. – mwasberg May 20 '16 at 7:33
• I also had \stopcontents at the end of the document, is that needed? – mwasberg May 20 '16 at 7:38
• This is the two warnings i get: ! Undefined control sequence.\@calc@post@scan ...st@scan \else \def \calc@next{\calc@error #1}\fi \fi \f... ...ocontents{toc}{\setcounter{tocdepth}{1}} and ! Undefined control sequence.\@calc@post@scan ...fi \fi \fi \fi \fi \calc@next ...ocontents{toc}{\setcounter{tocdepth}{1}} – mwasberg May 20 '16 at 8:02
• in this case (end of document) \stopcontents is optional. – touhami May 20 '16 at 8:12
• As I can see it seems to be a problem with calc package please try with \addtocontents{toc}{\protect\setcounter{tocdepth}{0}} \addtocontents{ptc}{\protect\setcounter{tocdepth}{2}} – touhami May 20 '16 at 8:23