Text FormattingRemoving the section title "Contents"

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
bkarpuz
Posts: 124
Joined: Thu Dec 18, 2008 4:53 pm

Removing the section title "Contents"

Post by bkarpuz »

Dear friends,

Let me explain my problem.
I am using the command \tableofcontents, and I also need to have itself of Contents (as a section) in TOC.
So that I use the following code:

Code: Select all

\addcontentsline{toc}{section}{Contents}
\tableofcontents
But this time in the PDF output, when I click to Contents in TOC, it takes me to the previous section.
As I have checked the *.toc file, I saw that its key refers to the previous section.
I therefore updated my code as the following:

Code: Select all

\section*{\centering Contents}
\addcontentsline{toc}{section}{Contents}
\tableofcontents
This time the hyperlink works good but I have two titles of Contents, one created by me with the command \section* and the other one created automatically by the command \tableofcontents.
How can I remove the one created automatically?
Or is there another way to handle this situation?

Thanks.

bkarpuz

Recommended reading 2024:

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

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

bkarpuz
Posts: 124
Joined: Thu Dec 18, 2008 4:53 pm

Removing the section title "Contents"

Post by bkarpuz »

bkarpuz wrote:Dear friends,

Let me explain my problem.
I am using the command \tableofcontents, and I also need to have itself of Contents (as a section) in TOC.
So that I use the following code:

Code: Select all

\addcontentsline{toc}{section}{Contents}
\tableofcontents
But this time in the PDF output, when I click to Contents in TOC, it takes me to the previous section.
As I have checked the *.toc file, I saw that its key refers to the previous section.
I therefore updated my code as the following:

Code: Select all

\section*{\centering Contents}
\addcontentsline{toc}{section}{Contents}
\tableofcontents
This time the hyperlink works good but I have two titles of Contents, one created by me with the command \section* and the other one created automatically by the command \tableofcontents.
How can I remove the one created automatically?
Or is there another way to handle this situation?

Thanks.

bkarpuz
Here is the solution I figured out myself.

Code: Select all

\def\contentsname{\empty}
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Removing the section title "Contents"

Post by frabjous »

The usual way of dealing with this is to use \phantomsection beforehand.

Code: Select all

\phantomsection%
\addcontentsline{toc}{section}{Contents}%
\tableofcontents
If sections always begin on a new page, you'll need to use \clearpage as well:

Code: Select all

\clearpage\phantomsection%
\addcontentsline{toc}{section}{Contents}%
\tableofcontents
(You might need to use \cleardoublepage instead for a two-sided document.)

The only problem with doing it your way is that it might be tricky to get the "Contents" header to match the style and position of the other section headings, and using an empty \contentsname might result in a space being put in for an empty heading where you don't want one.
bkarpuz
Posts: 124
Joined: Thu Dec 18, 2008 4:53 pm

Removing the section title "Contents"

Post by bkarpuz »

Thank you frabjous, your code is actually what I was looking for.

Many thanks again.

bkarpuz
Post Reply