Question
How can I add text to a table of contents, yet limit its scope to that specific table, and whose format can be manipulated and does not have a page number?
Conditions
- I can hide it from
\localtableofcontents
- I can show it in a specific
\localtableofcontents
and hide from\tableofcontents
- I can add a bookmark to it (and a page reference to the page where the following content starts (in my case this would be the same page as Statement 1)
Attempts
I realized shortly after trying to fulfill the first criterion that I was at a standstill. The following describes my attempt.
-
\addcontentsline{toc}{part}{Special Documents}
-
\addtocontents{toc}{\vspace{4ex}\protect\noindent\parbox[t]{\textwidth}{\Huge\textcolor{red}{Special Documents}}\par}
Number 1 allows me to take advantage of the fact that my current setup makes parts only visible in the global ToC. This is not ideal, because it removes flexilibilty. Most importantly, this adds an entry, but the entry is not formatted and the entry also has a page number.
Number 2 allows me to add a nice, formatted, non-numbered title to my table of contents. However, it adds it to every local table of contents, which is not good.
\documentclass{article}
\usepackage{fontspec}
\usepackage{etoc}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{hyperref}
\usepackage{bookmark}
\newcommand{\inputlanguage}[2]{%
\newpage\pdfbookmark{#1}{bkm#1}%
\etoctoccontentsline{part}{#1}%
#2
}%
\newcommand{\inputotherdoc}[2]{%
\newpage\pdfbookmark{#1}{bkm#1}%
\etoctoccontentsline{part}{#1}%
#2
}%
\begin{document}
\setcounter{tocdepth}{0} % make ToC only contain Parts
\renewcommand{\contentsname}{\protect\noindent\parbox[t]{\textwidth}{\Huge\textcolor{red}{Language Directory}}\par} % In reality formatting is done with tocloft
\tableofcontents
\renewcommand{\contentsname}{Table of Contents}
\setcounter{tocdepth}{4} % reset back to default for local ToCs
\newpage
\inputlanguage{da}{\localtableofcontents\section{At vove er, at miste fodfæstet for en stund ikke at vove er, at miste sig selv}}
\lipsum[1]
\inputlanguage{de}{\localtableofcontents\section{Wer rastet, der rostet.}}
\lipsum[1]
\inputlanguage{en}{\localtableofcontents\section{Education is what remains after one has forgotten what one has learned in school.}}
\lipsum[1]
% Problem is here
\addcontentsline{toc}{part}{Special Documents} % I need to inject text here and be able to: change font, change size, change, add new paragraphs, remove page number (imitate the the Language Directory text (using titlesec in original document)
\addtocontents{toc}{\vspace{4ex}\protect\noindent\parbox[t]{\textwidth}{\Huge\textcolor{red}{Special Documents}}\par} % Second Attempt
\inputotherdoc{Statement 1}{{\Huge Secret Information\par\bigskip}Here is some top-secret, specialized text.}
\inputotherdoc{Statement 2}{{\Huge Specialized Information\par\bigskip}Here is some highly specialized text.}
\end{document}
Output
In the example below, the "Special Documents" should only appear in the language ToC (\tableofcontents
) and not in the local ToCs.
Best Answer
The simplest technique is to add a command to the
.toc
file via\addtocontents{toc}{\protect\mycommand}
and then get this\mycommand
to perform some action and redefine itself to do nothing. This needs no package.However I use
etoc
to illustrate that the\localtableofcontents
will not have the extra heading. (not shown in the image which only illustrates the main TOC)If one needs the Special Documents in a later TOC, not the first one, then one should for example do in the preamble:
Then just before the TOC where one wants the Special Documents heading to appear one does: