部分名稱位於目錄中央,沒有編號和頁碼

部分名稱位於目錄中央,沒有編號和頁碼

我正在課堂上編寫文檔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} 

在此輸入影像描述

相關內容