Generalhide subsection from table of contents

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
ma501th
Posts: 50
Joined: Tue Apr 08, 2008 7:31 pm

hide subsection from table of contents

Post by ma501th »

hi,

i was wondering if there is any way the subsection be hidden in toc but still appear in the report with the numerical number i.e 1.2.1

i have tried inserting \subsection*{test}

the heading hides from the toc but appears with no numbers in the report.


DO you if there is a way?

thanks
ma501th

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

hide subsection from table of contents

Post by Stefan Kottwitz »

Hi,
you can hide all subsections inside the toc if you set the counter tocdepth to 1:

Code: Select all

\setcounter{tocdepth}{1}
Just in case if you mean just one certain subsection, but other should appear in the toc, that possible too, example:

Code: Select all

\documentclass[a4paper,10pt]{book}
\begin{document}
\tableofcontents
\chapter{One}
\section{One}
\subsection{One}
\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
\subsection{Two}
\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
\subsection{Three}
\end{document}
But if you want to hide all subsections, forget the second, the single line above is the right then.

Stefan
ma501th
Posts: 50
Joined: Tue Apr 08, 2008 7:31 pm

Re: hide subsection from table of contents

Post by ma501th »

Hi im abit confused on the above code.

if i just want to hide ONE particular subsection of the toc but the number to appear in the report of that particlaur subsection, which code of line should i apply and where

thanks
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

hide subsection from table of contents

Post by Stefan Kottwitz »

Hi ma501th,

then try to use my second example.

Code: Select all

% hide subsections in the toc:
\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
\subsection{This subsection is numbered but not shown in the toc}
\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
%from now on subsections are shown like usual
Stefan
ma501th
Posts: 50
Joined: Tue Apr 08, 2008 7:31 pm

Re: hide subsection from table of contents

Post by ma501th »

what does the numbers in curly brackets indicate?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

hide subsection from table of contents

Post by Stefan Kottwitz »

That's the value I'm setting to tocdepth. tocdepth=1 means, parts and chapters and sections will be shown inside the toc. tocdepth=2 means subsections too. tocdepth=3 means subsubsections too etc.

You will find further explanation here.

Stefan
Post Reply