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 5 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

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.