
Я пишу документ в book
классе и хочу, чтобы название частей было в центре TOC. Они также должны отображаться без номера части и без номеров страниц. Я видел некоторые решения для других классов, но они, похоже, не работают. Код
\documentclass{book}
\usepackage{titlesec}
\makeatletter
\renewcommand*\l@part[2]{%
\ifnum \c@tocdepth >-2\relax
\addpenalty{-\@highpenalty}%
\addvspace{2.25em \@plus\p@}%
\setlength\@tempdima{3em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
{\leavevmode
\hspace*{\fill}\centering\large\bfseries #1\hspace*{\fill}\llap{#2}}\par
\nobreak
\global\@nobreaktrue
\everypar{\global\@nobreakfalse\everypar{}}%
\endgroup
\fi}
\makeatother
\renewcommand{\partname}{}
\makeatletter
\titleformat{\part}[display]
{\Huge\scshape\filright\centering}
{}
{20pt}
{\thispagestyle{empty}}
\makeatother
\begin{document}
\tableofcontents
\part{This is a part of a document}
\end{document}
размещает название детали по центру, но как избавиться от цифр?
решение1
Это гораздо проще сделать, titletoc
чем возиться с зашифрованным кодом:
\documentclass{book}
\usepackage[newparttoc]{titlesec}
\usepackage{titletoc} %
\titleformat{\part}[display]
{\Huge\scshape\filright\centering}
{}
{20pt}
{\thispagestyle{empty}}
\titlecontents{part}[0pt]{\addvspace{2pc}\centering\large\bfseries}{}{}{}%
\begin{document}
\tableofcontents
\part{This is a part of a document}
\chapter{Chapter Title}
\end{document}