I have a few appendices that I do not want to show in the TOC. Instead, in the TOC, I want a single entry named "AllAppendices" to be shown. This shall be an (unnumbered) chapter in the appendix. The real appendices shall be (numbered) chapters, but again, not in the TOC.
These two versions I have tried:
\documentclass{book}
\usepackage{hyperref}
\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}
%\renewcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup\addtocounter{chapter}{-1}\refstepcounter{chapter}}
\begin{document}
\tableofcontents
I want to be able to reference FirstAppendix: \ref{FirstAppendix}, \nameref{FirstAppendix}
\chapter{LastRealChapter}
\label{LastRealChapter}
\chapter*{AllAppendices (can be added to TOC manually)}
\appendix
\label{AllAppendices}
\cleardoublepage
\tocless
\chapter{FirstAppendix (numbered, but not in TOC)}
\label{FirstAppendix}
\end{document}
What I get is this:
nameref
never works correctly, it references "AllAppendices"ref
works in the second version, but not in the first- I get a warning in the second version: "destination with the same identifier (name{appendix.A}) has been already used, duplicate ignored"
So my questions are:
- How to do it properly?
- What are the implications of
\addtocounter{chapter}{-1}\refstepcounter{chapter}
?
The MWE can be simplified:
\documentclass{book}
\usepackage{hyperref}
\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}
\renewcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup\addtocounter{chapter}{-1}\refstepcounter{chapter}}
\begin{document}
\tableofcontents
I want to be able to reference Appendix like this: \ref{Appendix}, \nameref{Appendix}
\chapter*{SomethingElse}
\cleardoublepage
\appendix
\tocless\chapter{Appendix (numbered, but not in TOC)}
\label{Appendix}
\end{document}
Commenting out the \cleardoublepage
seems to help, at least for \ref
.
Edit: And it does work in my document. So is the bottom line "no \cleardoublepage
before \tocless
chapters"?
Best Answer
You don't need complicated patches. Just insert in the
.toc
file at suitable location a change to thetocdepth
counter.