1

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

enter image description here

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.

2

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.

enter image description here

\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{\cftdot}{} % no dot leaders
\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' 
\renewcommand{\cftchapafterpnum}{\vspace{1ex}} % add'l vertical whitespace

\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}
    \addcontentsline{toc}{section}{\hspace{2em}Solved Problems}
    \section*{Supplementary Problems}
    \addcontentsline{toc}{section}{\hspace{2em}Supplementary Problems}

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

\end{document}
2

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}
\addtotoclist[\jobname]{toc}
\renewcommand\tableofcontents{\listoftoc[{\contentsname}]{toc}}% \addxcontentsline can be used
\setuptoc{toc}{numberline}% indent unnumbered entries added with \addxcontentsline

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

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

\DeclareTOCStyleEntry[
  indent=\mylen,
  linefill=\hfill,% no dots before page number
  onstarthigherlevel=\addvspace{.5em plus 1pt}\LastTOCLevelWasLower% add vertical space before first section in chapter
]{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}
\addxcontentsline{toc}{section}{Solved Problems}% use \addxcontentsline
\section*{Supplementary Problems}
\addxcontentsline{toc}{section}{Supplementary Problems}% use \addxcontentsline

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

enter image description here

1

Hope the below tags may helps you:

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

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

\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

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.