删除目录中零件编号后的点

删除目录中零件编号后的点

我想删除目录中零件编号后面的点。到目前为止,只有 Koma-Script 类有效。

\documentclass{mwbk}
\usepackage{titletoc}


\titlecontents{part}
[0pt]
{\addvspace{2pc}%
    \bfseries\centering}%
{\contentsmargin{0pt}%
    \bfseries
    \huge \partname~\thecontentslabel
    \\[12pt]%
    \Large\itshape}
{\contentsmargin{0pt}%
    \huge}
{%\quad\contentspage
    }
%[\addvspace{.5pc}]

%I've also tried this, it didn't work
%\usepackage{tocloft}
%\renewcommand{\cftpartaftersnum}{}
%%\renewcommand{\cftpartaftersnum}{:}
%\renewcommand\cftpartpresnum{Part~}


\begin{document}

\tableofcontents    
\part{title}
\end{document}

答案1

为了titletoc使用它,\part您必须重新定义parttitlesec 中的格式,以便它产生与类相同的结果。以下是一次尝试:

\documentclass{mwbk}

\usepackage[toctitles, newparttoc]{titlesec}
\usepackage{titletoc}
\titleformat{\part}[display]{\bfseries\filcenter}{\huge\partname~\Roman{part}}{30pt}{\Large\itshape}
\titlecontents{part}
[0pt]
{\addvspace{2pc}%
    \bfseries\centering}%
{\contentsmargin{0pt}%
    \bfseries
    \huge \partname~\thecontentslabel
    \\[12pt]%
    \Large\itshape}
{\contentsmargin{0pt}%
    \huge}
{,\quad\contentspage
    }
[\addvspace{.5pc}]

\begin{document}

\tableofcontents
\part{title}
\chapter{ first chapter}

\end{document} 

在此处输入图片描述

答案2

该类实际上与或mwbk不兼容。似乎需要较低级别的策略。titletoctocloft

\documentclass{mwbk}

\makeatletter
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \mw@tocskip{-1}{.6\baselineskip}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode\normalsize
       %\def\numberline##1{##1\enspace}% <--- removed
       \let\numberline\partnumberline  % <--- added
       \hfil\bfseries #1\hfil\null %\hb@xt@\@pnumwidth{\hss #2}%
      }\par
      \nobreak
      \global\@nobreaktrue
      \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
    \addvspace{.4\baselineskip}%
  \fi}
\def\partnumberline#1{\@partnumberline#1\@nil}
\def\@partnumberline#1.#2\@nil{#1#2\enspace}
\makeatother

\begin{document}

\tableofcontents

\part{title}
\chapter{title}
\end{document}

的重新定义\numberline与默认定义不同。基本上,我们现在删除了句点,隔离了句点前后的内容。

在此处输入图片描述

更短一点,如下etoolbox

\documentclass{mwbk}
\usepackage{etoolbox}

\makeatletter
\patchcmd{\l@part}
  {\def\numberline}
  {\let\numberline\partnumberline\def\blurbunused}
  {}{}
\def\partnumberline#1{\@partnumberline#1\@nil}
\def\@partnumberline#1.#2\@nil{#1#2\enspace}
\makeatother

\begin{document}

\tableofcontents

\part{title}
\chapter{title}
\end{document}

补丁需要定义一个宏,因为 的部分##1不能像这样被修补。更好的方法是regexpatch

\documentclass{mwbk}
\usepackage{regexpatch}

\makeatletter
\xpatchcmd{\l@part}
  {\def\numberline##1{##1\enspace}}
  {\let\numberline\partnumberline}
  {}{}
\def\partnumberline#1{\@partnumberline#1\@nil}
\def\@partnumberline#1.#2\@nil{#1#2\enspace}
\makeatother

\begin{document}

\tableofcontents

\part{title}
\chapter{title}
\end{document}

如果你想在一行写上“第一部分”,在下一行写上“标题”,并且居中,那么请先考虑清楚;如果你坚持这样做,

\documentclass{mwbk}

\makeatletter
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \mw@tocskip{-1}{.6\baselineskip}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode\normalsize\normalfont\bfseries
       \let\numberline\partnumberline  % <--- added
       \centering #1\par
      }
      \nobreak
      \global\@nobreaktrue
      \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
    \addvspace{.4\baselineskip}%
  \fi}
\def\partnumberline#1{\@partnumberline#1\@nil}
\def\@partnumberline#1.#2\@nil{\partname\ #1\\*}
\makeatother

\begin{document}

\tableofcontents

\part{title}
\chapter{title}
\end{document}

在此处输入图片描述

我的观点是,只有在非常特殊的情况下才应该使用部件。也许你的情况是这样的,也许不是。无论如何,强调太多了……

相关内容