3

I will be referring to the mwe below:

\documentclass[11pt,twoside,openany]{book}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{xparse}
\let\oldsubsection\subsection
\RenewDocumentCommand{\subsection}{s o m}{%
  \IfBooleanTF{#1}
    {\oldsubsection*{#3}%
     \addcontentsline{ptc}{subsection}{#3}}
    {\IfValueTF{#2}
       {\oldsubsection[#2]{#3}}
       {\oldsubsection{#3}}}
}
\usepackage{lipsum}

\begin{document}
\tableofcontents
\chapter{Content only from section}
The ToC below should not contain the subsection* title class rather the sections only.
\startcontents[chapters]
\printcontents[chapters]{}{1}{} % allows printing of subsection only
\section{A test section}
\lipsum[1-2]
\section*{Content from subsection*}
\startcontents[sections]
\printcontents[sections]{}{2}{} % allows printing of subsection only

\clearpage

\section{Test section in ToC}\lipsum[1]
\subsection*{Test subsection now in ToC}\lipsum[2]
\subsection*{Test subsection in ToC}\lipsum[3]
\stopcontents[chapters]
\end{document}

This question is more than likely related to the previous ones I have made earlier. Here is what I wish to achieve:

Chapter 1
mini ToC with sections only
Section 1
mini ToC with subsections* only

Seemingly, using \stopcontents[mytoc] and \stopcontents[mytocc] can possibly help but picture the document I am working on is one that has many chapters and many sections with many subsections*.

How can achieve the desired result?

1
  • 1
    \printcontents[chapters]{}{1}{} % allows printing of subsection only what do you exactly show here? only sections? sections and subsections?
    – touhami
    Jun 24, 2016 at 6:33

2 Answers 2

1

This command will be usefule:

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

You can use this to eliminate a section or subsection or ... from content list as follow:

\tocless\section{a section}

where the section is disappear on content list.

1
  • It does eliminate the subsection* from the section ToC under the chapter but it also eliminates from the subsection* ToC under each section.
    – azetina
    Jun 24, 2016 at 1:35
1

Here is a solution. We use

\printcontents[chapters]{}{1}{\setcounter{tocdepth}{1}}

for chapter minitoc to show only sections and

\printcontents[sections]{}{2}{
\setcounter{tocdepth}{2}
\section*{Content from subsection*}}

for section minitoc to show only subsections

Note that i use here \section*{Content from subsection*} inside \printcontents i think it's better like this.

\documentclass[11pt,twoside,openany]{book}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{xparse}
\let\oldsubsection\subsection
\RenewDocumentCommand{\subsection}{s o m}{%
  \IfBooleanTF{#1}
    {\oldsubsection*{#3}%
     \addcontentsline{ptc}{subsection}{#3}}
    {\IfValueTF{#2}
       {\oldsubsection[#2]{#3}}
       {\oldsubsection{#3}}}
}
\usepackage{lipsum}

\begin{document}
\tableofcontents
\chapter{Content only from section}
The ToC below should not contain the subsection* title class rather the sections only.
\startcontents[chapters]
\printcontents[chapters]{}{1}{\setcounter{tocdepth}{1}} 
\section{A test section}
\lipsum[1-2]
\startcontents[sections]
\printcontents[sections]{}{2}{
\setcounter{tocdepth}{2}
\section*{Content from subsection*}} % allows printing of subsection only

\clearpage

\section{Test section in ToC}\lipsum[1]
\subsection*{Test subsection now in ToC}\lipsum[2]
\subsection*{Test subsection in ToC}\lipsum[3]
\stopcontents[chapters]
\end{document}

You must log in to answer this question.

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