2

I have the simple following document:

\documentclass[10pt,a4paper]{report}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}
\usepackage{algorithm,algcompatible}
\begin{document}
    \tableofcontents
    \listoffigures
    \listoftables
    \listofalgorithms

\chapter{Chapter First}
This is my chapter first.

\chapter{Chapter Two}   
This is my chapter two.

\section{sec 1}

\begin{table}
    \centering
    \caption{my table}
    \label{tab1}
    \begin{tabular}{|c|c|}
        \hline 1 & 2 \\ 
        \hline 3 & 4 \\ 
        \hline 
    \end{tabular} 
\end{table}

\subsection{subsec 1}

\begin{algorithm}
    \caption{(\textit{The EGl-FOM})}
    \label{myalg}
    \begin{algorithmic}[1]
        \STATE Choose 
        \STATE Use the 
        \STATE Compute $\alpha_m$
        \STATE Compute $\lVert R_m\rVert_F=h_{m, m+1}|e_m^T\alpha_m|$.
    \end{algorithmic}
\end{algorithm}

\subsubsection{subsubsec 1}

\end{document}

I am going to hide chapter, section, subsection and subsubsection titles about chapter two from table of contents. Furthermore, I want to hide tables, figures and algorithms titles about chapter two from list of tables, figures and algorithms. Is there a proper way to do these things?

2
  • The hiding of chapter two is easy, but not the stealth mode for figures etc.
    – user31729
    Commented Dec 28, 2016 at 17:03
  • So you want everything to set as usual, except chapter two, which should only set in the main document, but not the corresponding ToC/LoF/LoT/LoA. Correct?
    – Werner
    Commented Dec 28, 2016 at 19:14

4 Answers 4

4

You can set a trigger before chapter two to stop writing content to the ToC/LoF/LoT/LoA and then restore this writing after chapter two (just before chapter three).

The two macros \hidefromtoc and \writetotoc are the triggers that stop/restore writing to the tables:

\documentclass{report}
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}
\usepackage{algorithm,algcompatible}

\let\oldaddcontentsline\addcontentsline
\newcommand{\hidefromtoc}{\renewcommand{\addcontentsline}[3]{}}
\newcommand{\writetotoc}{\let\addcontentsline\oldaddcontentsline}

\begin{document}

\tableofcontents
\listoffigures
\listoftables
\listofalgorithms

\chapter{First chapter}
\section{First section}
\subsection{First subsection}
\begin{figure}
  \caption{A figure}
\end{figure}
\begin{table}
  \caption{A table}
\end{table}
\begin{algorithm}
  \caption{An algorithm}
\end{algorithm}

\hidefromtoc% <------------ Stop writing content to ToC/LoF/LoT/LoA

\chapter{Second chapter}
\section{Second section}
\subsection{Second subsection}
\begin{figure}
  \caption{A figure}
\end{figure}
\begin{table}
  \caption{A table}
\end{table}
\begin{algorithm}
  \caption{An algorithm}
\end{algorithm}

\writetotoc% <------------ Restore writing content to ToC/LoF/LoT/LoA

\chapter{Third chapter}
\section{Third section}
\subsection{Third subsection}
\begin{figure}
  \caption{A figure}
\end{figure}
\begin{table}
  \caption{A table}
\end{table}
\begin{algorithm}
  \caption{An algorithm}
\end{algorithm}

\end{document}
0
2

The KOMA-Script classes provide two special features, that could be used to suppress ToC entries only:

  • Headings with empty ToC entry will not be printed in the ToC
  • The ToC entry of a heading can be set separately from the heading or the running head
\documentclass[headings=optiontotocandhead]{scrartcl}

\usepackage{lipsum}
\begin{document}

\tableofcontents
\section{First Section}
\lipsum[1]
\subsection{Subsection with ToC entry}
\lipsum[2]
\subsection[tocentry={}]{Subsection without ToC entry}
\lipsum[3]
\subsection{Another Subsection with ToC entry}

\end{document}

enter image description here

Package caption provides a similar feature for floats:

\documentclass[headings=optiontotocandhead]{scrartcl}
\usepackage{caption}
\usepackage{mwe}
\begin{document}

\tableofcontents
\listoffigures

\section{First Section}
\lipsum[1]
\subsection{Subsection with ToC entry}
\lipsum[2]
\begin{figure}
  \centering
  \includegraphics{example-image-a}
  \caption{Figure with ToC entry}
\end{figure}
\subsection[tocentry={}]{Subsection without ToC entry}
\lipsum[3]
\begin{figure}
  \centering
  \includegraphics{example-image-b}
  \caption[]{Figure without ToC entry}
\end{figure}
\subsection{Another Subsection with ToC entry}
\lipsum[4]
\begin{figure}
  \centering
  \includegraphics{example-image-c}
  \caption{Another figure with ToC entry}
\end{figure}

\end{document}

enter image description here

I've used scrartcl, the article class of KOMA-Script, for the example, because it is able to show table of contents and list of figures on one page. But the feature is also available for scrreprt and scrbook.

BTW: The classes provide option emulatestandardclasses to emulate the look-a-like of the standard classes.

1

A rather adhoc - approach, with \HideFromToC and \UnhideFromToC macros, changing the local tocdepth as well as the behaviour what is done inside \caption.

\documentclass[10pt,a4paper]{report}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{xpatch}
\usepackage{algorithm,algcompatible}


\newcounter{oldtocdepth}
\newif\ifshowintoc


\makeatletter


\xpatchcmd{\@caption}{%
 \addcontentsline{\csname ext@#1\endcsname}{#1}%
 {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
}{%
  \ifshowintoc
  \addcontentsline{\csname ext@#1\endcsname}{#1}%
  {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
  \fi
}{}{}



% Now adapt float's caption a little bit. 
\renewcommand\caption{%
  \ifshowintoc
  \ifx\@captype\@undefined
  \@latex@error{\noexpand\caption outside float}\@ehd
  \expandafter\@gobble
  \else
  \refstepcounter\@captype
  \let\@tempf\@caption
  \expandafter\ifx\csname @float@c@\@captype\endcsname\relax\else
  \expandafter\expandafter\let
  \expandafter\@tempf\csname @float@c@\@captype\endcsname\fi\fi
  \else
  \refstepcounter\@captype
  \let\@tempf\@caption
  \fi
  \@dblarg{\@tempf\@captype}%
}

\newcommand{\HideFromToC}[1][-1]{%
  \setcounter{oldtocdepth}{\number\value{tocdepth}}% Store the oldtocdepth
  \addtocontents{toc}{\protect\setcounter{tocdepth}{#1}}
  \showintocfalse
}

\newcommand{\UnhideFromToC}{%
  \addtocontents{toc}{\protect\setcounter{tocdepth}{\number\value{oldtocdepth}}}
  \showintoctrue
}

\makeatother

\begin{document}


\tableofcontents
\listoffigures
\listoftables
\listofalgorithms

\chapter{Chapter First}
This is my chapter first.



\HideFromToC


\chapter{Chapter Two}   
This is my chapter two.

\section{sec 1}

\begin{figure}
  \caption{A dummy figure}
\end{figure}

\begin{table}
    \centering
    \caption{my table}
    \label{tab1}
    \begin{tabular}{|c|c|}
        \hline 1 & 2 \\ 
        \hline 3 & 4 \\ 
        \hline 
    \end{tabular} 
\end{table}

\subsection{subsec 1}

\begin{algorithm}
    \caption{(\textit{The EGl-FOM})}
    \label{myalg}
    \begin{algorithmic}[1]
        \STATE Choose 
        \STATE Use the 
        \STATE Compute $\alpha_m$
        \STATE Compute $\lVert R_m\rVert_F=h_{m, m+1}|e_m^T\alpha_m|$.
    \end{algorithmic}
\end{algorithm}

\subsubsection{subsubsec 1}


\UnhideFromToC

\chapter{Foo that appears in ToC}

\section{Foo section}
\subsection{Foo subsection}
\subsubsection{Foo subsubsection}


\begin{algorithm}
    \caption{Another algo caption}
    \label{myalgo}
    \begin{algorithmic}[1]
        \STATE Choose 
        \STATE Use the 
        \STATE Compute $\alpha_m$
        \STATE Compute $\lVert R_m\rVert_F=h_{m, m+1}|e_m^T\alpha_m|$.
    \end{algorithmic}
\end{algorithm}


\end{document}
0
1

Writing the switch \addtocontents{toc}{\setcounter{tocdepth}{nn}} before a section level one wants to hide, and \addtocontents{toc}{\setcounter{tocdepth}{pp}} immediately after does the trick.

Here's an example with some subsections hidden in the article class: \documentclass[12pt]{article}% http://ctan.org/pkg/amsproc

    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
\usepackage{geometry}
    \usepackage{garamondx}
\usepackage{parskip}
\usepackage{verse}
\setlength{\leftmargini} {8em}
\renewcommand{\thesubsection}{\Alph{subsection}}
\raggedbottom
    \begin{document}

%\setcounter{tocdepth}{0}
\tableofcontents
    \section{Animals}

    \subsection{The Absolutely Abstemious Ass,}
\begin{verse}%
 who resided in a Barrell, and only lived on\\
Soda Water and Pickled Cucumbers. \\[3ex]
\includegraphics[scale=0.70]{nr_a}
\end{verse}

 \setcounter{subsection}{3}
    \subsection{The Dolomphious Duck,}
\begin{verse}
 who caught Spotted Frogs for her dinner \\
 with a Runcible Spoon. \\[2ex]
 \includegraphics[scale=0.75]{nr_d}
\end{verse}

 \setcounter{subsection}{7}
 \subsection{The Hasty Higgeldipiggledy Hen,}
\begin{verse}
 who went to market in a Blue Bonnet and Shawl, \\
 and bought a Fish for her Supper \\[3ex]
 \includegraphics[scale=0.75]{nr_h}
\end{verse}

 \setcounter{subsection}{15}
\subsection{The Perpendicular Purple Polly,}
 \begin{verse}
 who read the Newspaper and ate Parsnip Pie \\
 with his Spectacles. \\[3ex]
 \includegraphics[scale=0.75]{nr_p}
\end{verse}

\addtocontents{toc}{\setcounter{tocdepth}{1}}
\stepcounter{subsection}
\subsection{The Rural Runcible Raven,}
\begin{verse}
 who wore a White Wig and flew away\\
 with the Carpet Broom. \\[3ex]
 \includegraphics[scale=0.65]{nr_r}
\end{verse}
\addtocontents{toc}{\setcounter{tocdepth}{2}}

\setcounter{tocdepth}{2}
 \setcounter{subsection}{21}
\subsection{The Visibly Vicious Vulture,}
\begin{verse}
 who wrote some Verses to a Veal-cutlet in a\\
 Volume bound in Vellum. \\[2ex]
 \includegraphics[scale=0.6]{nr_v}
\end{verse}

 \setcounter{subsection}{24}
\subsection{ The Yonghy-Bonghy-Bo,}
\begin{verse}
 whose head was ever so much bigger than his\\
 Body, and whose Hat was rather small. \\[2ex]
 \includegraphics[scale=0.65]{nr_y}
\end{verse}

\end{document} 

enter image description here enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .