[Tex/LaTex] Suppress page numbers when using \addcontentsline

memoirtable of contents

I have a table of contents in my memoir book. I want there to be one line for each chapter, in addition to headings for each set of similar chapters.

However, I do not want any page numbers to be displayed across from the "headings" (for which I am using the command \addcontentsline).

In the following MWE, for example, I do not want a page number for "Topic 1" or "Topic 2".

\documentclass{memoir}
\begin{document}

\frontmatter
\tableofcontents*

\mainmatter

\phantomsection
\addcontentsline{toc}{part}{Topic 1}

\chapter{Chapter 1}

This is the first chapter.

\phantomsection
\addcontentsline{toc}{part}{Topic 2}

\chapter{Chapter 2}
This is the second chapter.

\chapter{Chapter 3}
This is the third chapter.

\end{document}

Best Answer

Instead of using \addcontentsline, you can use

\cftaddtitleline{<ext>}{<kind>}{<text>}{<page>}

to write a \contentsline entry of type <kind> into the file with extension <ext>; this line will typeset <text> and will use <page> as the page number. A little example:

\documentclass{memoir}

\begin{document}

\tableofcontents*

\cftaddtitleline{toc}{chapter}{Topic 1}{}
\chapter{Chapter One}

\cftaddtitleline{toc}{chapter}{Topic 2}{}
\chapter{Chapter Two}

\end{document}

enter image description here

Related Question