0

To meet the requirements of our school, I need the style of contents table like below:

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)

I tried titlesec, titletoc and tocloft package, but they will change all 'chapter' or 'section'. The Abstract, Introduction, Ack and Appendix, all use 'chapter', however, I need Abstract has leaders and page number, Introduction has neither leaders nor page number, Ack and Appendix have leaders and page number(and page number in parentheses).

Is there anyway to do this?

1

Unfortunaly there is no MWE in the question, but here is a suggestion using package 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}

Result:

enter image description here

  • Thank you very much! I deem it's a good solution. However, in my OS I meet error "! Undefined control sequence. l.6 \DeclareTOCStyleEntry". I searched that KOMA-Script is contained in TeXLive, I don't know what's wrong. And my TeXLive version is "2014.20141024-2+deb8u1", which shown by aptitude show texlive. – BDGong May 18 '18 at 1:19
  • Now I know why, KOMA-Script adds \DeclareTOCStyleEntry at version 3.20, TeXLive doesn't contain it until 2016. – BDGong May 18 '18 at 1:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.