\raggedbottom       %reduce underfull \vbox

\usepackage{titlesec, titletoc}
\titleformat{\part}[frame]{\normalfont\huge\bfseries}{\partname\ \thepart }{20pt}{\Huge\centering}

 %This is my trial!!!!!I also try to change \chaptername to \chaptertitlename

%customize page layout
\usepackage[a4paper, left=3cm, right=3cm]{geometry}


%page headers and footers   left,right,odd,even

% add mini-ta­bles-of-con­tents (mini­tocs) at the be­gin­ning of ev­ery chap­ter, part or sec­tion.

%revise\@endpart macro

\title{\Huge C++ Notes}

%initialize minitoc



\chapter{Getting Started}
    \section{Writing a Simple C++ Program}
        \subsection{Compiling and Executing Our Program}
    \section{A First Look at Input/Output}
    \section{A Word about Comments}
    \section{Flow of Control}
        \subsection{The while Statement}
        \subsection{The for Statement}
        \subsection{Reading an Unknown Number of Inputs}
        \subsection{The if Statement}
    \section{Introducing Classes}   
        \subsection{The Sales\_item Class}
        \subsection{A First Look at Member Functions}
    \section{The Bookstore Program}
    \section*{Chapter Summary} \markright{Chapter Summary} \addcontentsline{toc}{section}{Chapter Summary}
    \section*{Defined Terms} \markright{Defined Terms} \addcontentsline{toc}{section}{Defined Terms}

\part{The Basics}
\chapter{Variables and Basic Types}
    \section{Primitive Built-in Types}
        \subsection{Arithmetic Types}
        \subsection{Type Conversions}

\chapter{The Library}

\chapter{New features in C++11}


I want to add "Chapter" and chapter label before each chapter(within mainmatter) in table of contents, such as "Chapter 1 Getting Started","Chapter 2 Variables and Basic Types". However, my code always adds "Chapter" before chapter within backmatter.

enter image description here



{\chaptername\ \thecontentslabel\enskip}{}% <- changed

to insert "Chapter" and the chapter label for numbered chapters:

enter image description here

Note that there are warnings regarding the incompatibility of minitoc and titlesec.


This did the trick for me: using your MWE, in the snippet which you entilted 'your trial', add {\chaptername\ \thecontentslabel:\quad} in front of {\chaptername} (where before you had {}).

{\chaptername\ \thecontentslabel:\quad}{\chaptername~}

This leads to:

enter image description here

Of course, you can change some details, e.g. remove \quad in case you don't like the space after the colon etc.

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.