I am writing a document where I do not want subsection numbering to show in the TOC (I want the subsection heading visible in the TOC) but I want the subsection numbering to show in the actual document heading.
This is what I want
Table of Contents
1. Chapter One
1.1 Section One
SubSection One
Chapter 1
Chapter One
Some chapter text
1.1 Section One
Some text
1.1.1 Subsection One
Some text
I tried using \setcounter{secnumdepth}{1} but this removes the number even from the section heading so what I have is,
Table of Contents
1. Chapter One
1.1 Section One
SubSection One
Chapter 1
Chapter One
Some chapter text
1.1 Section One
Some text
Subsection One
Some text
Is it possible to get the section number in the document heading but not in the TOC entry?
In a latex example (using the “article” class), I get this in the .toc file:
The important part here is the
\numberlinemacro. Redefining it to something empty likewill remove all numberings in the toc and not elsewhere.
If you get something like
\tocsubsectioninstead in the .toc (see other answer), then you can probably do something like:However, this removes all numbers in the table of contents. If you want to control at which level the numbering disappear, the
\contentslinemacro expands to different macros depending on the context, e.g.,\l@section. Those macros in turn use the generic\@dottedtoclinemacro. This is the one you need to modify, in which we will conditionally redefine\numberline.To have control on the depth at which to stop displaying numbers, let us define a new counter:
Then the conditional redefinition will be following line (extracted from the code for more readability).
I simply copy-pasted the definition of
\@dottedtoclinefrom thelatex.ltxsource file, and added the check inside. Here is the code for the whole example:Final note: this will make the title of section and subsection to start at the same horizontal position, since there is no number to display. If you want more padding, you can for instance add
\quadto the new definition of\numberline, or to even use the original definition with just the#1removed: