How to hide/show section levels in the table of contents?











up vote
27
down vote

favorite
8












I have a table of contents (tableofcontents) in my document. How can I hide subsections in it? I want that only names of sections are displayed there.










share|improve this question




















  • 4




    Write subsection*{} with the asterisk, for a single case, or include setcounter{tocdepth}{1} in your preamble for anything below Section (subsections, subsubsections won't appear). I think this question has certainly come up before...
    – Alenanno
    Feb 5 '16 at 14:42








  • 2




    setcounter{tocdepth}{1} is quicker ;-)
    – Christian Hupfer
    Feb 5 '16 at 14:44










  • @Alenanno: Must --- resist--- to answer... this ToC question ;-)
    – Christian Hupfer
    Feb 5 '16 at 14:45










  • @ChristianHupfer I added it while you were posting lol
    – Alenanno
    Feb 5 '16 at 14:45






  • 4




    By the way, note that the asterisk will make the affected parts unnumbered!
    – Alenanno
    Feb 5 '16 at 14:47















up vote
27
down vote

favorite
8












I have a table of contents (tableofcontents) in my document. How can I hide subsections in it? I want that only names of sections are displayed there.










share|improve this question




















  • 4




    Write subsection*{} with the asterisk, for a single case, or include setcounter{tocdepth}{1} in your preamble for anything below Section (subsections, subsubsections won't appear). I think this question has certainly come up before...
    – Alenanno
    Feb 5 '16 at 14:42








  • 2




    setcounter{tocdepth}{1} is quicker ;-)
    – Christian Hupfer
    Feb 5 '16 at 14:44










  • @Alenanno: Must --- resist--- to answer... this ToC question ;-)
    – Christian Hupfer
    Feb 5 '16 at 14:45










  • @ChristianHupfer I added it while you were posting lol
    – Alenanno
    Feb 5 '16 at 14:45






  • 4




    By the way, note that the asterisk will make the affected parts unnumbered!
    – Alenanno
    Feb 5 '16 at 14:47













up vote
27
down vote

favorite
8









up vote
27
down vote

favorite
8






8





I have a table of contents (tableofcontents) in my document. How can I hide subsections in it? I want that only names of sections are displayed there.










share|improve this question















I have a table of contents (tableofcontents) in my document. How can I hide subsections in it? I want that only names of sections are displayed there.







table-of-contents






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 1 '17 at 21:23









egreg

699k8518613134




699k8518613134










asked Feb 5 '16 at 14:41









Lucky_girl

5351418




5351418








  • 4




    Write subsection*{} with the asterisk, for a single case, or include setcounter{tocdepth}{1} in your preamble for anything below Section (subsections, subsubsections won't appear). I think this question has certainly come up before...
    – Alenanno
    Feb 5 '16 at 14:42








  • 2




    setcounter{tocdepth}{1} is quicker ;-)
    – Christian Hupfer
    Feb 5 '16 at 14:44










  • @Alenanno: Must --- resist--- to answer... this ToC question ;-)
    – Christian Hupfer
    Feb 5 '16 at 14:45










  • @ChristianHupfer I added it while you were posting lol
    – Alenanno
    Feb 5 '16 at 14:45






  • 4




    By the way, note that the asterisk will make the affected parts unnumbered!
    – Alenanno
    Feb 5 '16 at 14:47














  • 4




    Write subsection*{} with the asterisk, for a single case, or include setcounter{tocdepth}{1} in your preamble for anything below Section (subsections, subsubsections won't appear). I think this question has certainly come up before...
    – Alenanno
    Feb 5 '16 at 14:42








  • 2




    setcounter{tocdepth}{1} is quicker ;-)
    – Christian Hupfer
    Feb 5 '16 at 14:44










  • @Alenanno: Must --- resist--- to answer... this ToC question ;-)
    – Christian Hupfer
    Feb 5 '16 at 14:45










  • @ChristianHupfer I added it while you were posting lol
    – Alenanno
    Feb 5 '16 at 14:45






  • 4




    By the way, note that the asterisk will make the affected parts unnumbered!
    – Alenanno
    Feb 5 '16 at 14:47








4




4




Write subsection*{} with the asterisk, for a single case, or include setcounter{tocdepth}{1} in your preamble for anything below Section (subsections, subsubsections won't appear). I think this question has certainly come up before...
– Alenanno
Feb 5 '16 at 14:42






Write subsection*{} with the asterisk, for a single case, or include setcounter{tocdepth}{1} in your preamble for anything below Section (subsections, subsubsections won't appear). I think this question has certainly come up before...
– Alenanno
Feb 5 '16 at 14:42






2




2




setcounter{tocdepth}{1} is quicker ;-)
– Christian Hupfer
Feb 5 '16 at 14:44




setcounter{tocdepth}{1} is quicker ;-)
– Christian Hupfer
Feb 5 '16 at 14:44












@Alenanno: Must --- resist--- to answer... this ToC question ;-)
– Christian Hupfer
Feb 5 '16 at 14:45




@Alenanno: Must --- resist--- to answer... this ToC question ;-)
– Christian Hupfer
Feb 5 '16 at 14:45












@ChristianHupfer I added it while you were posting lol
– Alenanno
Feb 5 '16 at 14:45




@ChristianHupfer I added it while you were posting lol
– Alenanno
Feb 5 '16 at 14:45




4




4




By the way, note that the asterisk will make the affected parts unnumbered!
– Alenanno
Feb 5 '16 at 14:47




By the way, note that the asterisk will make the affected parts unnumbered!
– Alenanno
Feb 5 '16 at 14:47










1 Answer
1






active

oldest

votes

















up vote
39
down vote



accepted










The tocdepth counter decides to which depth down the entries appear in the ToC.



(Code slightly edited, thanks to https://tex.stackexchange.com/users/1357/jdh for pointing me to a typo!)



Usually, following values hold





  • setcounter{tocdepth}{-1} -- only parts


  • setcounter{tocdepth}{0} -- only parts and chapters


  • setcounter{tocdepth}{1} -- part,chapters,sections


  • setcounter{tocdepth}{2} -- part,chapters,sections, subsections


  • setcounter{tocdepth}{3} -- part,chapters,sections, subsections,subsubsections


  • setcounter{tocdepth}{4} -- part,chapters,sections, subsections,subsubsections and paragraphs


  • setcounter{tocdepth}{5} -- part,chapters,sections, subsections, subsubsections, paragraphs and subparagraphs.


The memoir class adds the ToC depth -2 for the book structure level at all, being higher leveled than part.



This means, the larger the number for the counter, the greater the number of structuring in the ToC.



The toclevels can be found, for example in article.cls (and since book.cls loads article.cls) looking at the @startsection{...} commands.



If for example, some parts of the structuring should not appear in the ToC at all, there's a trick



addtocontents{toc}{setcounter{tocdepth}{-10}}


before the 'hidden parts' and later reenable them with



addtocontents{toc}{setcounter{tocdepth}{1}} 


See Switching tocdepth in the middle of a document for an example about changing the tocdepth in between.



Please do not confuse tocdepth with the secnumdepth counter!





Just for completeness: Both tocdepth and secnumdepth are counters that aren't defined withnewcounter, but have the internal names c@tocdepth and c@secnumdepth in order to allow setcounter etc. usage. You won't find them in the internal counter list and are no members of counter reset lists by default, which would be no of importance anyway.



The value of the tocdepth counter controls in the same manner which entries enter the regular bookmarks provided by hyperref.






share|improve this answer



















  • 1




    You are missing {toc} in the trick, in the second line where you reenable the level. (And thanks for this trick!)
    – JDH
    Aug 11 at 11:26












  • @JDH: Thanks for notifying -- I've corrected the typo.
    – Christian Hupfer
    20 hours ago











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f291307%2fhow-to-hide-show-section-levels-in-the-table-of-contents%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
39
down vote



accepted










The tocdepth counter decides to which depth down the entries appear in the ToC.



(Code slightly edited, thanks to https://tex.stackexchange.com/users/1357/jdh for pointing me to a typo!)



Usually, following values hold





  • setcounter{tocdepth}{-1} -- only parts


  • setcounter{tocdepth}{0} -- only parts and chapters


  • setcounter{tocdepth}{1} -- part,chapters,sections


  • setcounter{tocdepth}{2} -- part,chapters,sections, subsections


  • setcounter{tocdepth}{3} -- part,chapters,sections, subsections,subsubsections


  • setcounter{tocdepth}{4} -- part,chapters,sections, subsections,subsubsections and paragraphs


  • setcounter{tocdepth}{5} -- part,chapters,sections, subsections, subsubsections, paragraphs and subparagraphs.


The memoir class adds the ToC depth -2 for the book structure level at all, being higher leveled than part.



This means, the larger the number for the counter, the greater the number of structuring in the ToC.



The toclevels can be found, for example in article.cls (and since book.cls loads article.cls) looking at the @startsection{...} commands.



If for example, some parts of the structuring should not appear in the ToC at all, there's a trick



addtocontents{toc}{setcounter{tocdepth}{-10}}


before the 'hidden parts' and later reenable them with



addtocontents{toc}{setcounter{tocdepth}{1}} 


See Switching tocdepth in the middle of a document for an example about changing the tocdepth in between.



Please do not confuse tocdepth with the secnumdepth counter!





Just for completeness: Both tocdepth and secnumdepth are counters that aren't defined withnewcounter, but have the internal names c@tocdepth and c@secnumdepth in order to allow setcounter etc. usage. You won't find them in the internal counter list and are no members of counter reset lists by default, which would be no of importance anyway.



The value of the tocdepth counter controls in the same manner which entries enter the regular bookmarks provided by hyperref.






share|improve this answer



















  • 1




    You are missing {toc} in the trick, in the second line where you reenable the level. (And thanks for this trick!)
    – JDH
    Aug 11 at 11:26












  • @JDH: Thanks for notifying -- I've corrected the typo.
    – Christian Hupfer
    20 hours ago















up vote
39
down vote



accepted










The tocdepth counter decides to which depth down the entries appear in the ToC.



(Code slightly edited, thanks to https://tex.stackexchange.com/users/1357/jdh for pointing me to a typo!)



Usually, following values hold





  • setcounter{tocdepth}{-1} -- only parts


  • setcounter{tocdepth}{0} -- only parts and chapters


  • setcounter{tocdepth}{1} -- part,chapters,sections


  • setcounter{tocdepth}{2} -- part,chapters,sections, subsections


  • setcounter{tocdepth}{3} -- part,chapters,sections, subsections,subsubsections


  • setcounter{tocdepth}{4} -- part,chapters,sections, subsections,subsubsections and paragraphs


  • setcounter{tocdepth}{5} -- part,chapters,sections, subsections, subsubsections, paragraphs and subparagraphs.


The memoir class adds the ToC depth -2 for the book structure level at all, being higher leveled than part.



This means, the larger the number for the counter, the greater the number of structuring in the ToC.



The toclevels can be found, for example in article.cls (and since book.cls loads article.cls) looking at the @startsection{...} commands.



If for example, some parts of the structuring should not appear in the ToC at all, there's a trick



addtocontents{toc}{setcounter{tocdepth}{-10}}


before the 'hidden parts' and later reenable them with



addtocontents{toc}{setcounter{tocdepth}{1}} 


See Switching tocdepth in the middle of a document for an example about changing the tocdepth in between.



Please do not confuse tocdepth with the secnumdepth counter!





Just for completeness: Both tocdepth and secnumdepth are counters that aren't defined withnewcounter, but have the internal names c@tocdepth and c@secnumdepth in order to allow setcounter etc. usage. You won't find them in the internal counter list and are no members of counter reset lists by default, which would be no of importance anyway.



The value of the tocdepth counter controls in the same manner which entries enter the regular bookmarks provided by hyperref.






share|improve this answer



















  • 1




    You are missing {toc} in the trick, in the second line where you reenable the level. (And thanks for this trick!)
    – JDH
    Aug 11 at 11:26












  • @JDH: Thanks for notifying -- I've corrected the typo.
    – Christian Hupfer
    20 hours ago













up vote
39
down vote



accepted







up vote
39
down vote



accepted






The tocdepth counter decides to which depth down the entries appear in the ToC.



(Code slightly edited, thanks to https://tex.stackexchange.com/users/1357/jdh for pointing me to a typo!)



Usually, following values hold





  • setcounter{tocdepth}{-1} -- only parts


  • setcounter{tocdepth}{0} -- only parts and chapters


  • setcounter{tocdepth}{1} -- part,chapters,sections


  • setcounter{tocdepth}{2} -- part,chapters,sections, subsections


  • setcounter{tocdepth}{3} -- part,chapters,sections, subsections,subsubsections


  • setcounter{tocdepth}{4} -- part,chapters,sections, subsections,subsubsections and paragraphs


  • setcounter{tocdepth}{5} -- part,chapters,sections, subsections, subsubsections, paragraphs and subparagraphs.


The memoir class adds the ToC depth -2 for the book structure level at all, being higher leveled than part.



This means, the larger the number for the counter, the greater the number of structuring in the ToC.



The toclevels can be found, for example in article.cls (and since book.cls loads article.cls) looking at the @startsection{...} commands.



If for example, some parts of the structuring should not appear in the ToC at all, there's a trick



addtocontents{toc}{setcounter{tocdepth}{-10}}


before the 'hidden parts' and later reenable them with



addtocontents{toc}{setcounter{tocdepth}{1}} 


See Switching tocdepth in the middle of a document for an example about changing the tocdepth in between.



Please do not confuse tocdepth with the secnumdepth counter!





Just for completeness: Both tocdepth and secnumdepth are counters that aren't defined withnewcounter, but have the internal names c@tocdepth and c@secnumdepth in order to allow setcounter etc. usage. You won't find them in the internal counter list and are no members of counter reset lists by default, which would be no of importance anyway.



The value of the tocdepth counter controls in the same manner which entries enter the regular bookmarks provided by hyperref.






share|improve this answer














The tocdepth counter decides to which depth down the entries appear in the ToC.



(Code slightly edited, thanks to https://tex.stackexchange.com/users/1357/jdh for pointing me to a typo!)



Usually, following values hold





  • setcounter{tocdepth}{-1} -- only parts


  • setcounter{tocdepth}{0} -- only parts and chapters


  • setcounter{tocdepth}{1} -- part,chapters,sections


  • setcounter{tocdepth}{2} -- part,chapters,sections, subsections


  • setcounter{tocdepth}{3} -- part,chapters,sections, subsections,subsubsections


  • setcounter{tocdepth}{4} -- part,chapters,sections, subsections,subsubsections and paragraphs


  • setcounter{tocdepth}{5} -- part,chapters,sections, subsections, subsubsections, paragraphs and subparagraphs.


The memoir class adds the ToC depth -2 for the book structure level at all, being higher leveled than part.



This means, the larger the number for the counter, the greater the number of structuring in the ToC.



The toclevels can be found, for example in article.cls (and since book.cls loads article.cls) looking at the @startsection{...} commands.



If for example, some parts of the structuring should not appear in the ToC at all, there's a trick



addtocontents{toc}{setcounter{tocdepth}{-10}}


before the 'hidden parts' and later reenable them with



addtocontents{toc}{setcounter{tocdepth}{1}} 


See Switching tocdepth in the middle of a document for an example about changing the tocdepth in between.



Please do not confuse tocdepth with the secnumdepth counter!





Just for completeness: Both tocdepth and secnumdepth are counters that aren't defined withnewcounter, but have the internal names c@tocdepth and c@secnumdepth in order to allow setcounter etc. usage. You won't find them in the internal counter list and are no members of counter reset lists by default, which would be no of importance anyway.



The value of the tocdepth counter controls in the same manner which entries enter the regular bookmarks provided by hyperref.







share|improve this answer














share|improve this answer



share|improve this answer








edited 20 hours ago

























answered Feb 5 '16 at 14:59









Christian Hupfer

146k14188379




146k14188379








  • 1




    You are missing {toc} in the trick, in the second line where you reenable the level. (And thanks for this trick!)
    – JDH
    Aug 11 at 11:26












  • @JDH: Thanks for notifying -- I've corrected the typo.
    – Christian Hupfer
    20 hours ago














  • 1




    You are missing {toc} in the trick, in the second line where you reenable the level. (And thanks for this trick!)
    – JDH
    Aug 11 at 11:26












  • @JDH: Thanks for notifying -- I've corrected the typo.
    – Christian Hupfer
    20 hours ago








1




1




You are missing {toc} in the trick, in the second line where you reenable the level. (And thanks for this trick!)
– JDH
Aug 11 at 11:26






You are missing {toc} in the trick, in the second line where you reenable the level. (And thanks for this trick!)
– JDH
Aug 11 at 11:26














@JDH: Thanks for notifying -- I've corrected the typo.
– Christian Hupfer
20 hours ago




@JDH: Thanks for notifying -- I've corrected the typo.
– Christian Hupfer
20 hours ago


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f291307%2fhow-to-hide-show-section-levels-in-the-table-of-contents%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Accessing regular linux commands in Huawei's Dopra Linux

Can't connect RFCOMM socket: Host is down

Kernel panic - not syncing: Fatal Exception in Interrupt