# How to get table(s) of contents listed in itself (themselves) with etoc package?

Update: question precised and contextualized .

# Context

My real use case:

1. relies on many etoc features, among others multiple tables of contents,

2. needs table(s) of contents listed in themselves: I have 2 of them (easily achieved with etoc):

• the 1st one (at the beginning of the document) being just an outline (not so deep),
• the 2nd one (at the end of the document) being a detailed content (deeper).

Hence the 2nd TOC may be easily reached from the 1st one.

# Tested solution

An easy way to get a table of contents listed in itself is to use the tocbibind package. The trouble is, this package is incompatible with etoc. Indeed, as pointed out by the following examples:

• loading the former before the latter ruins the tocbibind features: the table of contents is not listed,
• loading the former after the latter ruins the etoc features: e.g. \etocsetnexttocdepth is ignored and only one TOC can be populated.

## tocbibind before etoc: former's features ruined (tables of contents not listed)

\documentclass{article}
\usepackage{tocbibind}
\usepackage{etoc}
\begin{document}
\etocsetnexttocdepth{section}
\tableofcontents
\section{A section}
\subsection{A subsection of a section}
\subsection{Another subsection of a section}
\section{Another section}
\subsection{A subsection of another section}
\subsection{Another subsection of another section}
\tableofcontents
\end{document}


## etoc before tocbibind: former's features ruined (\etocsetnexttocdepth ignored and 2nd TOC empty)

\documentclass{article}
\usepackage{etoc}
\usepackage{tocbibind}
\begin{document}
\etocsetnexttocdepth{section}
\tableofcontents
\section{A section}
\subsection{A subsection of a section}
\subsection{Another subsection of a section}
\section{Another section}
\subsection{A subsection of another section}
\subsection{Another subsection of another section}
\tableofcontents
\end{document}


# Question

I guess etoc package lets us display the table(s) of contents in table(s) of contents but how to do that (without the help of tocbibind which is incomptible)?

To use tocbibind with etoc you need \usepackage[nottoc]{tocbibind}.

Apart from that, perhaps this kind of code can help in your exact context.

\documentclass{article}
\usepackage{etoc}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\begin{document}
\etocsetnexttocdepth{section}
\tableofcontents
\etoctoccontentsline{section}{Table des mati\eres initiales}
\section{A section}
\subsection{A subsection of a section}
\subsection{Another subsection of a section}
\section{Another section}
\subsection{A subsection of another section}
\subsection{Another subsection of another section}
\tableofcontents
\etoctoccontentsline{section}{Table des mati\eres finales}
\end{document}

• I should have precised I tried \usepackage[nottoc]{tocbibind} which doesn't solve my problem. I'm a bit disappointed: etoc, this very nice and powerful package, needs to manually add lines to the .toc file in order to get table(s) of contents listed in itself (themselves)? Too bad! ;) Jun 20 '17 at 5:16
• there is indeed no such etoc option because the same document can use multiple \tableofcontents with completely different contexts and effect (see "Surprising uses of etoc" section in doc). On the other hand you have multiple possibilities to achieve it: as in my mwe, or using \etocsettocstyle to use a starred sectioning command and usual \addcontentsline, or to use \etocaftertitlehook ... Idea is that \etocsettocstyle is more or less rather mandatory when dealing with sub-tocs, as, for example in book, you don't want them to use \chapter or \chapter*.
– user4686
Jun 20 '17 at 6:24

After your edit, the finally interesting question is still unclear, at least to me.

My question would be, why do you want to include the line Table of Contents into the TOC? What extra information could the reader gain on that extra line? I'd say none.

Nevertheless, interpreting your code, it seems to me, as if you want to get rid of the subsections being displayed in the TOC. If that assumption is correct, you could use \setcounter{tocdepth}{N} to exclude everything beyond level N. In your case you need to choose N to be 1.

Here is my suggestion

\documentclass{article}
\usepackage{etoc}
\usepackage{tocbibind}
\begin{document}

%% Prevent the \subsections from being displayed in the TOC
\setcounter{tocdepth}{1}
\tableofcontents

\section{A section}
\subsection{A subsection of a section}
\subsection{Another subsection of a section}
\section{Another section}
\subsection{A subsection of another section}
\subsection{Another subsection of another section}
\end{document}


Resulting in

• Having table(s) of contents listed in themselves may be useful e.g. if you have 2 of them (easily achieved with etoc), the 1st one (at the beginning of the document) being just an outline (not so deep), the 2nd one (at the end of the document) being a detailed content (deeper): hence the 2nd TOC may be easily reached from the 1st one. Furthermore, I know I can achieve \etocsetnexttocdepth without etoc and just with \setcounter{tocdepth} but this was just an example of the etoc's features: my real case relies on many etoc other features (e.g. multiple tables of contents). Jan 19 '17 at 9:34
• @DenisBitouzé, please add this important information to your MWE and postulate a real question as "how to achieve this or that". It is important to be specific and clear, otherwise we only can guess.
– Jan
Jan 19 '17 at 9:44
• My question appeared quite clear to me :) but, anyway, I attempted to clarify it. Jan 19 '17 at 10:49