0

In my project, I tried to hide the subsection from table of content by using the code \setcounter{tocdepth}{1} but it didn't worked

\documentclass[12pt,a4paper]{report}
\usepackage[utf8]{inputenc, vietnam}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amsthm}

\renewcommand{\thesection}{\arabic{chapter}.\arabic{section}.}

\begin{document}

\clearpage \newpage \tableofcontents

\newpage \section{Linear Analysis} \setcounter{tocdepth}{1} \subsection{Definition}

\end{document}

How can I hide the subsection from table of content ? Thank you

PermQi
  • 187
  • Do you want to hide all subsections or just a single one? – samcarter_is_at_topanswers.xyz Dec 12 '23 at 14:39
  • Note that all sectional entries are actually written to the TOC no matter the value of tocdepth. It the executing of \tableofcontents that uses the value of tocdepth. Meaning it you only want to remove one subsection, the adjustment of tocdepth need to go into the .toc file. – daleif Dec 12 '23 at 14:50
  • You have\setcounter{tocdepth}{1} after \tableofcontents so it has no effect. – David Carlisle Dec 12 '23 at 14:51
  • @daleif I don't follow what you meant, can you show the code in concrete ? – PermQi Dec 12 '23 at 14:53
  • @DavidCarlisle I tried putting ``\setcounter{tocdepth}{1}right before\tableofcontents```, but it still didn't worked, so what should I do – PermQi Dec 12 '23 at 14:56
  • 1
    When I move \setcounter{tocdepth}{1} up before \tableofcontents and remompile (maybe twice) I only see Linear Analysis in the toc. Without it I see both. – daleif Dec 12 '23 at 15:01
  • 1
    Can you please clarify if you want to remove all subsections or just a single subsection? – samcarter_is_at_topanswers.xyz Dec 12 '23 at 15:03
  • it will work (normally you set it in the preamble, but anywhere before \tableofcontents is OK) – David Carlisle Dec 12 '23 at 15:07
  • @samcarter_is_at_topanswers.xyz I want to remove all subsections – PermQi Dec 12 '23 at 15:12
  • @DavidCarlisle I have tried as you said
    \documentclass[12pt,a4paper]{report}
    \usepackage[utf8]{inputenc, vietnam}
    \usepackage{amsfonts}
    \usepackage{amsmath}
    \usepackage{amsthm}
    
    \renewcommand{\thesection}{\arabic{chapter}.\arabic{section}.}
    \setcounter{tocdepth}{1}
    
    \begin{document}
    
    \clearpage
    \newpage
    \tableofcontents
    
    \newpage
    \section{Linear Analysis}
    \subsection{Definition}
    
    \end{document}
    

    and I still see the subsection in the table of content. I don't know why (I make my project on overleaf)

    – PermQi Dec 12 '23 at 15:16
  • @PermQi You need \setcounter{tocdepth}{1}, like you write in your question. Not \setcounter{tocdepth}{2} – samcarter_is_at_topanswers.xyz Dec 12 '23 at 15:18
  • 1
    you have \setcounter{tocdepth}{2} so you have set it to 2 – David Carlisle Dec 12 '23 at 15:18
  • @samcarter_is_at_topanswers.xyz I have tried 1 and 2 aswell, they have no effect – PermQi Dec 12 '23 at 15:20
  • @PermQi Only use 1, don't use 2 at all. – samcarter_is_at_topanswers.xyz Dec 12 '23 at 15:22
  • @DavidCarlisle I don't know if the issue may come from the fact that I compile my project on overleaf, since I have tried everything you guilded me but it still didn't worked – PermQi Dec 12 '23 at 15:22
  • With just 1 it works fine: https://www.overleaf.com/read/psttwftqftgh#7227eb – samcarter_is_at_topanswers.xyz Dec 12 '23 at 15:23
  • no if you set it to 2 it will not work. it is nothing to do with overleaf – David Carlisle Dec 12 '23 at 15:27
  • @samcarter_is_at_topanswers.xyz oh you're right, it worked, I still have no idea why while I have tried that way too and at that point it still didn't worked – PermQi Dec 12 '23 at 15:27

0 Answers0