为了满足我们学校的要求,我需要像下面这样的目录样式:
Preface ..................... I
Abstract .................... II
1 Introduction
1.1 Section 1 ............... (1)
1.2 Section 2 ............... (3)
2 Another Chapter
2.1 Section 1 ............... (6)
2.2 Section 2 ............... (8)
.
.
.
Ack .........................(54)
References ..................(56)
Appendix 1 ..................(58)
Appendix 2 ..................(60)
我尝试了titlesec
和titletoc
包tocloft
,但它们会更改所有“章节”或“部分”。摘要、简介、确认和附录都使用“章节”,但是,我需要摘要有前导和页码,简介既没有前导也没有页码,确认和附录有前导和页码(以及括号中的页码)。
有什么办法可以做到这一点吗?
答案1
不幸的是,问题中没有 MWE,但这里有一个使用包的建议tocbasic
。
\documentclass{book}
\usepackage{blindtext}% only for dummy text
\usepackage{tocbasic}
\DeclareTOCStyleEntry[
linefill=\tocchapterlinefill,
entryformat=\normalfont,pagenumberformat=\normalfont,
beforeskip=0pt plus .2pt% no additional space before chapter entries
]{tocline}{chapter}
\newcommand*\tocchapterlinefill{\TOCLineLeaderFill}
\newcommand*\tocchapterdotson{\def\tocchapterlinefill{\TOCLineLeaderFill}}
\newcommand*\tocchapterdotsoff{\def\tocchapterlinefill{\hfill}}
\usepackage{expl3}
\ExplSyntaxOn
\clist_map_inline:nn
{chapter,section,subsection,subsubsection,paragraph,subparagraph}
{\DeclareTOCStyleEntry[indent=0pt,pagenumberbox=\tocpagenumberbox]{tocline}{#1}}
\ExplSyntaxOff
\newcommand*\tocpagenumberbox[1]{\makebox[2.5em][r]{\tocpagenumber{#1}}}
\newcommand*\tocpagenumber[1]{#1}
\newcommand*\tocpagenumberparentheseson{\renewcommand\tocpagenumber[1]{(##1)}}
%\newcommand*\tocpagenumberparenthesesoff{\renewcommand\tocpagenumber[1]{##1}}
\usepackage{xpatch}
\xapptocmd\mainmatter{%
\addtocontents{toc}{\protect\tocpagenumberparentheseson}%
\addtocontents{toc}{\protect\tocchapterdotsoff}%
}{}{\mainmatterPatchFailed}
\xapptocmd\backmatter{%
\addtocontents{toc}{\protect\tocchapterdotson}%
}{}{\backmatterPatchFailed}
\begin{document}
\frontmatter
\pagenumbering{Roman}
\chapter{Preface}
\chapter{Abstract}
\tableofcontents
\mainmatter
\Blinddocument
\Blinddocument
\backmatter
\chapter{Ack}
\end{document}
结果: