5

I want to put part name in center of TOC as MODULE - I with out page number.

\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage{tocstyle}
\renewcommand{\partname}{Module}%

\usetocstyle{standard}
%\settocfeature{pagenumberhook}{}
\renewcommand*{\addparttocentry}[2]{%
  \addtocentrydefault{part}{}{\protect\parbox{\textwidth}{\protect\centering#2}}% original #1 in second argument
}


\begin{document}

\tableofcontents

\part{A}
\chapter{chapter A}
\section{Section a}
\lipsum
\part{B}
\chapter{chapter B}
\section{Section b}
\lipsum
\end{document}
sandu
  • 7,950

2 Answers2

3

You can redefine \l@part as implemented in scrbook.cls:

\documentclass{scrbook}

\renewcommand\partname{Module}

\makeatletter
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty{-\@highpenalty}%
    \addvspace{2.25em \@plus\p@}%
    \setlength{\@tempdima}{2em}%
    \if@tocleft
      \ifx\toc@l@number\@empty\else
        \setlength\@tempdima{0\toc@l@number}%
      \fi
    \fi
    \begingroup
      \leavevmode
      \centering\usekomafont{partentry}{\partname\ -- #1\nobreak
        \usekomafont{partentrypagenumber}{}}\null\par
      \ifnum \scr@compatibility>\@nameuse{scr@v@2.96}\relax
      \endgroup
      \penalty20010
      \else
          \penalty\@highpenalty
      \endgroup
    \fi
  \fi
}\makeatother

\begin{document}

\tableofcontents
\part{Test Part One} 
\chapter{Test Chapter}
\section{Test Section}
\part{Test Part Two} 
\chapter{Test Chapter}
\section{Test Section}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • I am not able to format TOC with tocstyle when i use above code. – sandu Jul 04 '13 at 04:50
  • @sandu that's not enough information. If you want to, you can edit your original question and add there a simple document showing the relevant settings you are using (those for tocstyle`) and showing the problems with the proposed solutions. – Gonzalo Medina Jul 04 '13 at 17:20
  • MWE is added in the question – sandu Jul 05 '13 at 06:15
  • Solution: http://tex.stackexchange.com/questions/122373/how-to-remove-page-number-in-toc-for-part-entry-not-page-number-printed-in-toc?noredirect=1#comment273682_122373 – sandu Jul 05 '13 at 06:17
  • @sandu I don't understand. If you already solved the problem, then there's no need for the comments nor for the edit. Please rollback the edit to your question and leave it ss it initially was. Had I known about the other questio I wouldn't have suggested the edit in the first place. – Gonzalo Medina Jul 05 '13 at 11:13
3

Instead of redefining l@part you can hack l@part with \addtokomafont:

\addto\captionsenglish is used to redefine the partname. See: Change reports text for bibliography

\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage{lipsum}
\addto\captionsenglish{%
 \renewcommand{\partname}{Module}%
}

\makeatletter
\addtokomafont{partentry}{\def\numberline#1{--~#1\autodot\quad}\centering\partname~}
\addtokomafont{partentrypagenumber}{\let\hfil\relax\def\hb@xt@#1#2{}}
\makeatother
\begin{document}

\tableofcontents

\part{A}
\chapter{chapter A}
\section{Section a}
\lipsum
\part{B}
\chapter{chapter B}
\section{Section b}
\lipsum
\end{document}
Marco Daniel
  • 95,681