1

My document has both starred and non-starred version of section, and I want to add both types to my table of contents. I am using titletoc and I tried to solve it as follows:

\titleformat{\section}[hang]
{\Large\bfseries}
{}{0em}{\MakeUppercase{#1}}

\titleformat{name=\section,numberless}[block]
{\large\filcenter\bfseries}
{}{0em}{#1\addcontentsline{toc}{section}{#1}}

\titlecontents*{section}[0em]{\normalsize}{}{}{~\thecontentspage}
[, ][.\vspace{0.5em}]

This almost works as I want, apart from two problems:

  1. When I use a \section* in my document, I get the following warning:

Package hyperref Warning: The anchor of a bookmark and its parent's must not (hyperref) be the same. Added a new anchor on input line 160.

  1. Sometimes in the generated table of contents, there is a space between the end of the section heading and the comma separating it from the next heading, like this:

PART 1: A PART HEADING 1

A section heading 1, A starred section heading 1 , another section heading 1.

I tried changing the end of my titlecontents definition to:

[\unskip, ][.\vspace{0.5em}]

which did get rid of some of the undesired spaces, but not all of them. I have no idea what is causing the extra space to be generated. Help!

0

2 Answers 2

0

I would suggest you create your own sectioning commands:

\newcommand{\nonumsection}[1]{\section*{#1}%
\addcontentsline{toc}{section}{#1}}

You need to create one command for nonum-chapter, -subsection, etc. That's how I always do it.

1
  • Thanks for the suggestion. I tried it but it didn't solve either of the issues.
    – Michael D.
    Mar 12, 2016 at 18:02
0

OK, with a lot of trial and error I finally figured out a solution.

To get rid of the hyperref warning : use \phantomsection :

\titleformat{name=\section,numberless}[block]                                             
% how to handle \section*
{\large\filcenter\bfseries}
{}{0em}{#1\phantomsection\addcontentsline{toc}{section}{#1}}

To get rid of the space that appears before the comma separator when section* entries appear in the TOC :

Even though I am not displaying subsection or lower in the TOC:

\protect\setcounter{tocdepth}{1}

it is still necessary to define a \titlecontents line for subsection and subsubsection. Then the mysterious spaces vanish.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .