[Tex/LaTex] Remove entries from short ToC but not from long ToC

appendicesshorttoctable of contentstitletoc

Please find a minimal example illustrating this question below.

The problem is this:

  • There is only one appendix chapter, which is divided into several paragraphs. These paragraphs should appear in the detailed ToC (made possible using the shorttoc package) but not in the short ToC.
  • In the detailed ToC appendix paragraphs (but only appendix(!!) paragraphs) should appear as sections meaning they are intended to be aligned on the same level as sections in the rest of the ToC.

The solution shown in the minimal example arised from the answers to two related questions I posted here. However, one problem is still unsolved:

How can I achieve in the code given below that the appendix sections(=paragraphs) do not figure in the short ToC (which currently they do since paragraphs actually are sections modified so that they look like paragraphs)?

I found several related problems on the web but in the end they amount to removing certain sections from ToC (see the parts of my code commented out). This of course has the consequence that they do not appear in the detailed ToC either since the detailed ToC gets its data from the .toc file …

I hope I made clear what the problem is!? Seems to me a quite tricky issue!

\documentclass[10pt, a4paper]{report}

\usepackage[titletoc]{appendix}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{shorttoc}
\usepackage{hyperref}

%\newcommand{\nocontentsline}[3]{}
%\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}

\begin{document}

\setcounter{secnumdepth}{3}                             

\renewcommand*\contentsname{Contents (detailed)}        

\pdfbookmark[1]{Contents}{toc}                          
\shorttoc{Contents}{1}                                  

\cleardoublepage                                        

\setcounter{tocdepth}{4}                                
\renewcommand*\contentsname{Contents (detailed)}        
\pdfbookmark[1]{Contents (detailed)}{toc (detailed)}    
\tableofcontents

\chapter{Test Chapter}
\section{Test Section}
\subsection{Test Subsection}
\subsubsection{Test Subsubsection}
\paragraph{Test Paragraph}

\begin{appendices}

\renewcommand\thechapter{}

\chapter{Test Appendix}

\titleformat{\section}[runin]
  {\normalfont\normalsize\bfseries}{}{1em}{}
\titlespacing*{\section}
  {0pt}{3.25ex plus 1ex minus .2ex}{1em}
\titlecontents{section}[1.5em]
  {}{}{}{\titlerule*[7.5pt]{.}\contentspage}

%\tocless\section{Test Section One}
\section{First section looking like a paragraph}
%\tocless\section{Test Section Two}
\section{Second section looking like a paragraph}

\end{appendices}

\end{document}

Best Answer

Possibly not the most elegant way:

  • Create a new boolean switch shorttoc,

  • Use the etoolbox package to patch the \@startshorttoc macro so that the shorttoc switch is set to true (inside a group),

  • At the start of the appendix, add a line to the .toc file setting the tocdepth counter to 0 if the shorttoc switch is true.


\documentclass[10pt, a4paper]{report}

\usepackage[titletoc]{appendix}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{shorttoc}
\usepackage{hyperref}

%\newcommand{\nocontentsline}[3]{}
%\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}

\usepackage{etoolbox}

\newbool{shorttoc}

\makeatletter
\patchcmd{\@startshorttoc}{\bgroup}{\bgroup\booltrue{shorttoc}}{}{}
\makeatother

\begin{document}

\setcounter{secnumdepth}{3}                             

\renewcommand*\contentsname{Contents (detailed)}        

\pdfbookmark[1]{Contents}{toc}                          
\shorttoc{Contents}{1}                                  

\cleardoublepage                                        

\setcounter{tocdepth}{4}                                
\renewcommand*\contentsname{Contents (detailed)}        
\pdfbookmark[1]{Contents (detailed)}{toc (detailed)}    
\tableofcontents

\chapter{Test Chapter}
\section{Test Section}
\subsection{Test Subsection}
\subsubsection{Test Subsubsection}
\paragraph{Test Paragraph}

\begin{appendices}

\addtocontents{toc}{\protect\ifbool{shorttoc}{\setcounter{tocdepth}{0}}{}}

\renewcommand\thechapter{}

\chapter{Test Appendix}

\titleformat{\section}[runin]
  {\normalfont\normalsize\bfseries}{}{1em}{}
\titlespacing*{\section}
  {0pt}{3.25ex plus 1ex minus .2ex}{1em}
\titlecontents{section}[1.5em]
  {}{}{}{\titlerule*[7.5pt]{.}\contentspage}

%\tocless\section{Test Section One}
\section{First section looking like a paragraph}
%\tocless\section{Test Section Two}
\section{Second section looking like a paragraph}

\end{appendices}

\end{document}

enter image description here

enter image description here