下面的例子定义了一个新版本,但\addcontentsline
没有显示\thepage
。不幸的是,当引入时编译失败hyperref
。我不知道为什么?
\documentclass[11pt,fleqn]{book}
%\usepackage{hyperref}
\makeatletter
\def\addcontentslinepart#1#2#3{\addtocontents{#1}{\protect\contentsline{#2}{#3}{}}}%
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >-2\relax
\refstepcounter{part}%
\addcontentslinepart{toc}{part}{\thepart\hspace{1em}#1}%
\else
\addcontentsline{toc}{part}{#1}%
\fi
\markboth{}{}%
\@endpart}
\makeatother
\begin{document}
\tableofcontents
\part{Title}
\chapter{Title}
\end{document}
答案1
这实际上并不是对您问题的答案(至少需要\@part
在加载之前重新定义hyperref
;有一种更简单的方法:重新定义\l@part
以忽略其第二个参数。
\documentclass[11pt,fleqn]{book}
\usepackage{etoolbox}
\usepackage{hyperref}
\makeatletter
\patchcmd\l@part{#2}{}{}{}
\makeatother
\begin{document}
\tableofcontents
\part{Title}
\chapter{Title}
\end{document}
如果你正在加载titletoc
,要修补的宏是\ttl@savel@part
:
\documentclass[11pt,fleqn]{book}
\usepackage{titletoc}
\usepackage{etoolbox}
\usepackage{hyperref}
\makeatletter
\patchcmd\ttl@savel@part{#2}{}{}{}
\makeatother
\begin{document}
\tableofcontents
\part{Title}
\chapter{Title}
\end{document}
答案2
\documentclass[11pt,fleqn]{book}
\usepackage{hyperref}
\makeatletter
\def\addcontentslinepart#1#2#3{\addtocontents{#1}{\protect\contentsline{#2}{#3}{}{\@currentHref}}}%
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >-2\relax
\refstepcounter{part}%
\addcontentslinepart{toc}{part}{\thepart\hspace{1em}#1}%
\else
\addcontentsline{toc}{part}{#1}%
\fi
\markboth{}{}%
\@endpart}
\makeatother
\begin{document}
\tableofcontents
\part{Title}
\chapter{Title}
\end{document}