Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have formatted a ToC with tocloft package. I have it almost right, but I would like to remove the numbers of the sections; just leave the section names. I am trying different commands but I can not find the right one. The problem is to maintain the number in the section themselves at the same time.

Any idea?

share|improve this question

1 Answer 1

up vote 7 down vote accepted

tocloft inserts \cftsecpresnum before placing the section number, and \cftsecaftersnum after it. These are hooks you can use to tie into and grab the number:

enter image description here

\documentclass{book}
\usepackage{tocloft}% http://ctan.org/pkg/tocloft
\makeatletter
\renewcommand{\cftsecpresnum}{\begin{lrbox}{\@tempboxa}}
\renewcommand{\cftsecaftersnum}{\end{lrbox}}
\makeatother
\begin{document}
\tableofcontents
\chapter{A chapter}
\section{First section}
\section{Second section}
\section{Last section}
\end{document}

We effective wrap the numbering mechanism of \section within the ToC inside a box \@tempboxa and store it, but never use it again. This gobbles the contents.

Note that this redefinition is global in terms of the section number display. It can be made local if you only want to display specific parts with/without section numbers. It also maintains the numbering width (set by \cftsecnumwidth). If this should be removed, add

\setlength{\cftsecnumwidth}{0pt}

to the document preamble as well.

share|improve this answer
    
I have a question: you already deleted the numbers in the contents table, but when you create the sections, the numbers still appear, is there a way to erase the numbers leaving just the title of the section? –  Oshnaj May 19 at 0:54
    
Should this approach work as well for the memoir class instead of the book class? I keep getting the following when trying to compile my document: ! LaTeX Error: \cftsecpresnum undefined. I can't just switch over to book based on how the rest of my document is structured (for the memoir class). I thought it worth asking here in case you knew before asking a separate question that is essentially the same one as OP's. (I looked at the tocloft package documentation but didn't really see anything there to fix my problem.) –  Daniel W. Farlow Jul 26 at 23:47
    
@DanielW.Farlow: memoir uses section not sec for ToC-entries related to \section. See Table 9.3 of the memoir user manual (p 150). Therefore, using \cftsectionpresnum and \cftsectionaftersnum works. Remember to remove the usepackage{tocloft} as memoir provides this/similar functionality. –  Werner Jul 27 at 16:21
    
@Werner Thanks so much for your response (saved me a lot of head scratching). Tried it out and it worked perfectly. Thanks again! –  Daniel W. Farlow Jul 27 at 16:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.