Try this:
\documentclass{scrbook}
\usepackage[ngerman]{babel}
\usepackage{lipsum}
\usepackage{tocloft}
\addtocontents{toc}{\cftpagenumbersoff{part}}
\renewcommand*{\addparttocentry}[2]{%
\addtocentrydefault{part}{}{\protect\parbox{\textwidth}{\protect\centering#2}}% original #1 in second argument
}
\begin{document}
\tableofcontents
\part{A}
\section{a}
\lipsum
\part{B}
\section{b}
\lipsum
\end{document}
Instead of \hfil
I used a \parbox
with centered contents, just in case some title would span more than one line. I suppresses the part number in the ToC with a simple redefinition of \addparttocentry
.
You mentioned that you need to use tocloft
, but if this is not the case, you can use the tocstyle
package (designed especifically for the KOMA
classes) instead and say something like:
\documentclass{scrbook}
\usepackage[ngerman]{babel}
\usepackage{lipsum}
\usepackage{tocstyle}
\usetocstyle{classic}
\settocfeature{pagenumberhook}{}
\renewcommand*{\addparttocentry}[2]{%
\addtocentrydefault{part}{}{\protect\parbox{\textwidth}{\protect\centering#2}}% original #1 in second argument
}
\begin{document}
\tableofcontents
\part{A}
\section{a}
\lipsum
\part{B}
\section{b}
\lipsum
\end{document}
Warning:
The following solution should be used only for old versions of KOMA-Script (for example, the one in TeX Live2009); for recent versions (those from TeX Live2010 on), please see the code above; I only include this solution here sice the OP is using TeX Live2009 and has no possibility to update:
\documentclass{scrbook}
\usepackage[ngerman]{babel}
\usepackage{lipsum}
\usepackage{tocloft}
\makeatletter
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >-2\relax
\refstepcounter{part}%
\@maybeautodot\thepart%
\addcontentsline{toc}{part}{\protect\makebox[0pt][l]{\protect\parbox{\textwidth}{\protect\centering#1}}}%
\else
\addcontentsline{toc}{part}{#1}%
\fi
\begingroup
\setparsizes{\z@}{\z@}{\z@\@plus 1fil}\par@updaterelative
\raggedpart
\interlinepenalty \@M
\normalfont\sectfont\nobreak
\ifnum \c@secnumdepth >-2\relax
\size@partnumber{\partformat}%
\partheadmidvskip
\fi
\size@part{#2}\strut%
\partmark{#1}\par
\endgroup
\@endpart
}
\makeatother
\addtocontents{toc}{\cftpagenumbersoff{part}}
\begin{document}
\tableofcontents
\part{A}
\section{a}
\lipsum
\part{B}
\section{b}
\lipsum
\end{document}
The Spanish module for babel
is responsible for this, probably following some directive of the authority on the language. There is an additional option for disabling it:
\usepackage[spanish,es-lcroman,es-nosectiondot]{babel}
See section 2.3 in the documentation for the Spanish option (texdoc spanish
or here on TeXdoc.net).
There will be no need to act on \@seccntformat
.
In order to keep the period after the chapter number (although I don't see why), patch the \@chapter
command:
\usepackage{etoolbox}
\makeatletter
\patchcmd\@chapter{\numberline{\thechapter}}{\numberline{\thechapter.}}{}{}
\makeatother
Best Answer
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: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, addto the document preamble as well.