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}

\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

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!

I would suggest you create your own sectioning commands:

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


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

• Thanks for the suggestion. I tried it but it didn't solve either of the issues. Mar 12 '16 at 18:02

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}

\protect\setcounter{tocdepth}{1}