# How to change the style of Contents to this when book documentclass is used

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?

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*\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}

\usepackage{xpatch}
\xapptocmd\mainmatter{%
}{}{\mainmatterPatchFailed}
\xapptocmd\backmatter{%
}{}{\backmatterPatchFailed}

\begin{document}
\frontmatter
\pagenumbering{Roman}
\chapter{Preface}
\chapter{Abstract}
\tableofcontents
\mainmatter
\Blinddocument
\Blinddocument
\backmatter
\chapter{Ack}
\end{document}


Result:

• 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