12

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}
3
  • 1
    Just a suggestion: I guess that \part is a proper way to do this. It typesets "Part" page and adds a ToC line. It might be a bit strange to have something in ToC that is not in the main document. The presence of parts does not affect chapter numbering at all.
    – yo'
    Commented Mar 30, 2012 at 6:50
  • @tohecz Thanks! Would you mind please explaining what the exact command would be, if I want to use \part to accomplish this in my MWE? Commented Mar 30, 2012 at 15:06
  • See daleif's answer below...
    – yo'
    Commented Apr 1, 2012 at 21:55

2 Answers 2

22

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

3
  • 8
    What would be a similar strategy with the book class?
    – pluton
    Commented Jan 28, 2015 at 8:13
  • 3
    Note: If you do not use the memoir class, you need to load the package tocloft for this solution to work; see tex.stackexchange.com/questions/179108/…
    – PhoemueX
    Commented Jan 3, 2019 at 15:12
  • This mwe doesn't compile for me. I get Undefined control sequence in main.toc on line \contentsline {chapter}{\chapternumberline {1}Chapter One}{3}{}% Commented Mar 14, 2023 at 10:39
1

If topics are part-like, then just use \part (restyle it if needed) and ask the TOC not to print part page numbers

3
  • 1
    Would you mind please explaining what the exact command would be, if I want to use \part to accomplish this in my MWE? Commented Mar 30, 2012 at 15:06
  • 1
    In your example now just add: \cftpagenumbersoff{part}. Using \part you will get a part page. If you want to remove the autogenerated part number in the toc: \renewcommand\partnumberline[1]{}
    – daleif
    Commented Mar 30, 2012 at 15:20
  • 5
    @daleif It is better to edit your answer to add some more details and explanations, instead of putting them into comments ;)
    – yo'
    Commented Apr 1, 2012 at 21:54

You must log in to answer this question.

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