# ToC custom format

I am seeking help in creating a custom ToC based of the following format:

But the default ToC does not allow me to change the settings. I know there is a titletoc package, but I have not been able to be successful with the understanding the settings.

Below is MWE:

\documentclass[11pt,twoside,openany]{book}
\begin{document}
%-------------------------------------------------------------------------------
\tableofcontents
\clearpage
\thispagestyle{empty}
%-------------------------------------------------------------------------------
\mainmatter
\chapter{chap1}
\section{sec1}
\subsection{subsec1}
\chapter{chap2}
\section{sec2}
\subsection{subsec2}
\end{document}


Any assistance given will appreciated.

Here's a tocloft-based solution.

• Note that I didn't do anything with the appearance of the "Table of Contents" header -- the default is a chapter-like unnumbered header named "Contents" -- since you didn't specify how this header should be typeset.

• I provide some code to show how unnumbered section-level headers might get typeset in the ToC.

• I assumed that subsection-level headers and below shouldn't be displayed in the ToC, as you screenshot doesn't how any such headers. If this assumption is not appropriate, please indicate how subsection-level headers should be displayed in the ToC.

\documentclass[11pt,twoside,openany]{book}
\usepackage[letterpaper,margin=1in]{geometry} % make some suitable choices
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}

\usepackage{tocloft}
\tocloftpagestyle{empty} % don't show page numbers in ToC
\renewcommand{\cftchapfont}{\sffamily\bfseries}
\newlength\mylen
\settowidth\mylen{\cftchapfont CHAPTER 1\quad} % calculate width of indentation
\setlength{\cftchapnumwidth}{\mylen}
\renewcommand{\cftchappagefont}{\cftchapfont}  % same font as for chapter headers
\renewcommand{\cftchappresnum}{\color{gray}CHAPTER } % use 'gray'

\cftsetindents{section}{\mylen}{2em} % indentation for section-level headers
%%\cftsetindents{subsection}{\dimexpr\mylen+2em\relax}{3em}
\setcounter{tocdepth}{1} % Don't show subsection-level headers and below in TOC

\begin{document}
\frontmatter % use lower-case roman numerals for page numbers in frontmatter
\tableofcontents
\clearpage
\thispagestyle{empty}

\mainmatter % switch to arabic numerals for page numbers

\chapter{Fundamental Operations with Numbers}
\section{Four Operations}
\section{System of Real Numbers}
\section{Graphical Representation of Real Numbers}
\subsection{subsec1}
\section*{Solved Problems}
\section*{Supplementary Problems}

\chapter{Other Operations}
\section{Section \thesection}
\subsection{subsec2}

\end{document}


Here is another suggestion using package tocbasic:

\documentclass[11pt,twoside,openany]{book}
%\usepackage[utf8]{inputenc}% only needed with older TeX-Distributions
\usepackage[T1]{fontenc}
\usepackage{xcolor}

\usepackage{scrextend}% pagestyle empty for interleaf pages
\usepackage{tocbasic}

\newcommand\chapterentryformat[1]{\bfseries\sffamily #1}
\newcommand\usechapterprefix[1]{\textcolor{gray}{\MakeUppercase{\chaptername}~#1}}
\newlength\mylen

\DeclareTOCStyleEntry[
entryformat=\chapterentryformat,
entrynumberformat=\usechapterprefix,
numwidth=\mylen
]{tocline}{chapter}

\DeclareTOCStyleEntry[
indent=\mylen,
linefill=\hfill,% no dots before page number
]{tocline}{section}
\setcounter{tocdepth}{1}

\begin{document}
\frontmatter
\tableofcontents

\mainmatter
\chapter{Fundamental Operations with Numbers}
\section{Four Operations}
\section{System of Real Numbers}
\section{Graphical Representation of Real Numbers}
\subsection{subsec1}
\section*{Solved Problems}
\section*{Supplementary Problems}

\chapter{Other Operations}
\section{Section \thesection}
\subsection{subsec2}
\end{document}


Hope the below tags may helps you:

\documentclass[11pt,twoside,openany]{book}
\usepackage{titlesec}
\usepackage{titletoc}

\titlecontents{chapter}
[0pt]
}%
{\contentsmargin{0pt}%
\bfseries
{\huge\chaptername~\thecontentslabel\enspace}%
\large}
{\contentsmargin{0pt}%
\large}
{\hfill\contentspage}

\titlecontents{section}
[114pt]
{}
{{\thecontentslabel}\enskip}
{}
{\titlerule*[.5pc]{.}\contentspage}

\setcounter{tocdepth}{1}
\begin{document}
%-------------------------------------------------------------------------------
\tableofcontents
\clearpage
\thispagestyle{empty}
%-------------------------------------------------------------------------------
\mainmatter
\chapter{chap1}
\section{sec1}
\subsection{subsec1}
\chapter{chap2}
\section{sec2}
\subsection{subsec2}
\end{document}

• If I go beyond 10 chapters, the chapter number occupies 1 em more and does not align. – azetina Jul 1 at 20:31
• @azetina Shall I correct and repost the answer? If yes, I'll proceed, hence there are many answers from some experts, so only I asked this... – MadyYuvi Jul 2 at 4:28
• You should for completeness of answer. – azetina Jul 2 at 18:12