# Make subsection visible in local TOC only, not in Main TOC

I am writing a large article type document with a series of complex appendices in it.

I have included a local table of contents with each appendix that lists the sections and subsections within that specific appendix (the local TOC for Appendix A lists only that appendix's subsections, etc) using tools from the etoc package.

What I would like to do is have my appendix sections contain numbered subsections/subsubsections, but have the subsections/subsubsections only appear in the appendix local TOC. However I still want the appendix sections to appear in the main TOC.

Here is a rough approximation of my setup:

\documentclass{article}

\usepackage{tocloft} % Adds tools for TOC customization
\usepackage{etoc} % Local toc
\usepackage[titletoc,title]{appendix}

\begin{document}

\setcounter{tocdepth}{3}
\tableofcontents

\section{First section}
\subsection{a Subsection}
\section{Second section}
\subsection{a Subsection}
\subsection{Another Subsection}

\begin{appendix}
\section{Appendix A} % <- I want this to appear in the main TOC
\etocsetnexttocdepth{2}
\localtableofcontents
\subsection{Appendix Subsection} % <- I want this to appear in the local TOC, but not the main TOC
\end{appendix}

\end{document}


And the output:

• @ChristianHupfer sorry, its loaded properly in my real document. This mockup is wrong. I'll fix that – enpaul Aug 2 '17 at 21:41

You can simply add an \addtocontents command to the main TOC reducing the tocdepth. Since you're using the etoc package, this is done with the \etocsettocdepth.toc command. You then have to tell the local table of contents to ignore the current tocdepth and use its own. This is done with \etocignoretoctocdepth. It seems easiest to put all of these commands at the beginning of the appendix environment. I've done this using the etoolbox package:

\documentclass{article}

\usepackage{tocloft} % Adds tools for TOC customization
\usepackage{etoc} % Local toc
\usepackage[titletoc,title]{appendix}
\usepackage{etoolbox}
\AtBeginEnvironment{appendix}{\etocsettocdepth.toc{section}\etocignoretoctocdepth
\etocsetnexttocdepth{subsection}}

\begin{document}

\setcounter{tocdepth}{3}
\tableofcontents

\section{First section}
\subsection{a Subsection}
\section{Second section}
\subsection{a Subsection}
\subsection{Another Subsection}

\begin{appendix}
\section{Appendix A} % <- I want this to appear in the main TOC
\localtableofcontents
\subsection{Appendix Subsection} % <- I want this to appear in the local TOC, but not the main TOC
\end{appendix}

\end{document}


(It seems to me that etoc is a replacement for tocloft so I'm not sure if they should be used together, but I've left the package in your document.)

• I couldn't seem to get this to work, but I may just be missing something. In your example output you also appear to have the heading for the 'Appendix Subsection' but not the local toc entry for it, is that correct? – enpaul Aug 3 '17 at 18:49
• @enpaul Sorry about that. I've updated the answer. – Alan Munn Aug 3 '17 at 19:27
• Thanks! That did it, except for some reason the first appendix still displayed the subsections in the main TOC. I reordered the appendices and the problem stayed with the first appendix. I verified your answer because it works in the sample test document just fine, there's just something in my document that's screwing with it. – enpaul Aug 3 '17 at 19:57
• @enpaul If you put the commands manually (not using the AtBeginEnvironment code), does it work? – Alan Munn Aug 3 '17 at 20:03
• If I put the line commands immediately before the first appendix's local TOC then it works perfectly, for both the first appendix and all the others. – enpaul Aug 3 '17 at 20:16