目录居中显示部分名称,无编号和页码

目录居中显示部分名称,无编号和页码

我正在课堂上写一篇文档book,想让各部分的名称在目录中居中显示。它们还应该不带部分编号和页码显示。我见过一些针对其他课程的解决方案,但这些似乎不起作用。代码

\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} 

在此处输入图片描述

相关内容