1

How can I remove page number of \chapter yet allow page numbers of \chapter* in the Table of Contents within using the report class?

  • I take it you mean the number shown on the the first page of the chapter. This depends on the document class, but most use \thispagestyle{plain} on the first page of the chapter. You might try using \thispagestyle{empty} after \chapter, or you can redefine plain style to not show the page number, or redefine \chapter to use \thispagestyle{empty}. – John Kormylo Aug 29 '18 at 16:28
2

In order to distinguish between the management of \chapter and \chapter* in the ToC, I've created two different hangling macros. The first is the traditional \l@chapter which I've replaced with something that discards its second argument - the page number. The second (for \chapter*) replicates what is done for \l@chapter (or \chapter) but just calls it \l@schapter.

The following minimal example has two chapters. The first is a regular \chapter, while the second is a \chapter*. The latter requires a manual insertion into the ToC using an schapter type (see Creating unnumbered chapters/sections (plus adding them to the ToC and/or header)).

enter image description here

\documentclass{report}

\makeatletter
\let\l@schapter\l@chapter % Copy \l@chapter into \l@schapter
\let\old@l@chapter\l@chapter % Copy \l@chapter into \old@l@chapter
\renewcommand{\l@chapter}[2]{\old@l@chapter{#1}{}}% Discard second argument of \l@chapter
\makeatother

\begin{document}

\tableofcontents

\chapter{A chapter}

\chapter*{Another chapter}
\addcontentsline{toc}{schapter}{Another chapter}

\end{document}
1

Here is a way to achieve what I think you are looking for, using nameref, tocloft and etoolbox.

It uses nameref to add the unnumbered chapters to the table of contents. After \chapter* you can see there are two lines I've added.

To remove the page numbers from numbered \chapter in the ToC, I've used tocloft and the \cftpagenumbersoff{chapter} and \cftpagenumberson{chapter} commands. Using etoolbox I've added \cftpagenumbersoff{chapter} before instances of \chapter and added \cftpagenumberson{chapter} immediately afterwards to restore numbering. Note that you have to use \@chapter to specifically apply this to \chapter only and not \chapter*.

Sources:

Adding unnumbered sections to TOC

Add chapter to TOC without page number

Is it possible to add a command at the beginning of a chapter?

enter image description here

\documentclass{report}
\usepackage{nameref}
\usepackage{tocloft}
\usepackage{etoolbox}

\makeatletter
\pretocmd{\@chapter}{% <--- IMPORTANT
\addtocontents{toc}{\cftpagenumbersoff{chapter}}% <--- IMPORTANT
}{}{}
\apptocmd{\@chapter}{% <--- IMPORTANT
\addtocontents{toc}{\cftpagenumberson{chapter}}% <--- IMPORTANT
}{}{}
\makeatother

\begin{document}

\tableofcontents

\chapter{A chapter}

\chapter*{Another chapter}
\label{chap:test}
\addcontentsline{toc}{chapter}{\nameref{chap:test}}

\chapter{And another chapter}

\end{document}
  • Thanks Milo. In addition to the solution you provided here, I am very grateful, but I also want the numbered chapters to be in the form CHAPTER ONE: INTRODUCTION in the table of content. – user169363 Sep 1 '18 at 16:16
  • It's better if you ask this as a separate question on the site. – Milo Sep 1 '18 at 18:21
0

I think I have found an answer to my question:

\documentclass[a4paper,12pt]{report}
\usepackage{graphicx,amsmath,amsthm,geometry} %enumerate% directly loaded from texstudio
\usepackage{lipsum} % for generating dummy texts
\usepackage{tocloft}  %for table of contents and list of figure formatting
\usepackage{fmtcount} % for textual representation of numbers
\usepackage{etoolbox} % for changing internal parameters of latex
\usepackage{fancyhdr}  % for pagestyles
\usepackage{times}    % for times new roman font
\usepackage[linktoc=all]{hyperref}   % for link to chapter and section. if you comment hyperref package, you must also comment all the \phantomsection in this code.
\usepackage{tikz} % for drawing
\usepackage{titletoc} %for table of content formatting

%%% this code centred, adjust chapters' distance from the title and convert chapter 1 to chapter one
    \makeatletter  
\def\@makechapterhead#1{%
    \vspace*{-60\p@}% default: 50pt % vertical distance between chapter and top of page
    {\parindent \z@ \centering \normalfont% default: \raggedright
        \ifnum \c@secnumdepth >\m@ne
        \huge\bfseries \@chapapp\space \NUMBERstring{chapter}%\the
        \par\nobreak
        \vskip 20\p@% default: 20\p@  % vertical distance between chapter and title below it
        \fi
        \interlinepenalty\@M
        \Huge \bfseries #1\par\nobreak
        \vskip 40\p@
}}
\def\@makeschapterhead#1{%
    \vspace*{-80\p@}% default: 50pt % vertical distance between unnumbered chapter and top of page
    {\parindent \z@ \centering% default: \raggedright
        \normalfont
        \interlinepenalty\@M
        \Huge \bfseries  #1\par\nobreak
        \vskip 40\p@
}}
\makeatother



%%% this code changes the names of contets, list of figures,abstract, chapters and references
\renewcommand{\contentsname}{\large{Table of Contents}}
\renewcommand{\listfigurename}{\large{List of Figures}}
\renewcommand{\abstractname}{\large{Abstract}}
\renewcommand{\bibname}{\large{References}}
\renewcommand{\chaptername}{\large{CHAPTER}}


%This code centres table of content
\renewcommand{\cfttoctitlefont}{\hfill\Large\bfseries}
\renewcommand{\cftaftertoctitle}{\hfill}

%This code centres list of figure
\renewcommand{\cftloftitlefont}{\hfill\Large\bfseries}
\renewcommand{\cftafterloftitle}{\hfill}

\linespread{1.8}

%this code redefines the chapter format in table of contents
\newlength{\len}
\titlecontents{chapter}[1.2em]{\bfseries}%\bfseries
{\contentslabel[\large{\chaptername} \NUMBERstringnum{\thecontentslabel}:]{3.6em}\settowidth{\len} {Chapter \NUMBERstringnum{\thecontentslabel}}\hspace*{\len}}%]
{\large{\thecontentslabel}\hspace*{-5.1cm}}%\contentslabel[]{}
{\hfill\contentspage}% replace \hfill with \cftdotfill{\cftdotsep} if you want dots in chapters in toc


% this code for list of figures with figure, cation and page.
\renewcommand{\cftafterloftitle}{\hfill{}
    \\[\baselineskip]\mbox{\textbf{Figure}}\hfill{\textbf{Caption}}\hfill{\normalfont \textbf{Page}}}


%this code removes the references label(their numbers) on the reference page
\makeatletter
\renewcommand\@biblabel[1]{}
\makeatother


\begin{document}

    \pagenumbering{roman}

    \fancyhf{}
    \fancyfoot[C]{\thepage}
    \pagestyle{fancy}
    \fancypagestyle{plain} 
    \fancyhf{}
    \fancyfoot[C]{\thepage}
    \renewcommand{\headrulewidth}{0pt}

\phantomsection 
\addcontentsline{toc}{chapter}{\numberline{}Title Page}
\chapter*{Title}

\newpage
\phantomsection
\addcontentsline{toc}{chapter}{\numberline{}Certification}

    \chapter*{\large{Certification}}

\newpage
\phantomsection
\addcontentsline{toc}{chapter}{\numberline{}Dedication}

    \chapter*{\large{Dedication}}


\newpage
\phantomsection
\addcontentsline{toc}{chapter}{\numberline{}Acknowledgements}

\chapter*{\large{Acknowledgements}}


\newpage

\phantomsection
\addcontentsline{toc}{chapter}{\numberline{}Table of Contents}
\setlength{\cftbeforetoctitleskip}{-2.5cm} %to control vertical spacing
\tableofcontents
\clearpage
\phantomsection
\addcontentsline{toc}{chapter}{\numberline{}List of Figures}
\setlength{\cftbeforeloftitleskip}{-2.5cm} %to control vertical spacing
\listoffigures 
\clearpage
\phantomsection
\addcontentsline{toc}{chapter}{\numberline{}Abstract}
\chapter*{\large{Abstract}}


\newpage
\phantomsection 
\addcontentsline{toc}{chapter}{\numberline{}Nomenclatures}

    \chapter*{\large{Nomenclatures}}


\newpage  
\pagenumbering{arabic}

%this code redefines the chapter format in table of contents
\titlecontents{chapter}[1.2em]{\bfseries}%\bfseries
{\contentslabel[\large{\chaptername} \NUMBERstringnum{\thecontentslabel}:]{3.6em}\settowidth{\len} {Chapter \NUMBERstringnum{\thecontentslabel}}\hspace*{\len}}%]
{\large{\thecontentslabel}\hspace*{-5.1cm}}%\contentslabel[]{}
{\hfill\cftpagenumbersoff{chapter}}% 

\chapter{\large{INTRODUCTION}}

\fancyhf{}
%\fancyhead[C]{\thepage}
\pagestyle{fancy}
\fancypagestyle{plain} 
\fancyhf{}
\fancyhead[C]{\thepage}
\renewcommand{\headrulewidth}{0pt}
%\pagenumbering{arabic}
\setcounter{page}{1}
\section{Introduction}

\section{Section 1}
\subsection{Subsection 1}
\subsection{Subsection 2}


\section{Section 2} 

\chapter{\large{LITERATURE REVIEW}}
\section{Section 1}

\section{Section 2}

 \chapter{\large{RESEARCH METHODOLOGY}}  
\section{Section 1}

\section{Section 2}



 \section{Section 3}

\chapter {\large{RESULTS AND DISCUSSION}}
\section{Section 1}
\section{Section 2}
\section{Section 3}

\chapter {\large{CONCLUSION}}
\section{Summary}
\section{Conclusion}
\section{Recommendation}
\newpage
\phantomsection

%this code redefines the chapter format in table of contents
\titlecontents{chapter}[1.2em]{\bfseries}
{\contentslabel[\large{\chaptername} \NUMBERstringnum{\thecontentslabel}:]{3.6em}\settowidth{\len} {Chapter \NUMBERstringnum{\thecontentslabel}}\hspace*{\len}}%]
{\large{\thecontentslabel}\hspace*{-5.1cm}}
{\hfill\contentspage}%

\addcontentsline{toc}{chapter}{\numberline{} REFERENCES}
\thispagestyle{empty}
\begin{thebibliography}{99}
\bibitem{1} First reference
\bibitem{2} Second reference
\bibitem{3} Third reference
\bibitem{4} Fourth reference
\bibitem{5} Fifth reference
\end{thebibliography}

\end{document}
  • Can somebody help me put the latex code above properly on stack exchange for others to use. – user169363 Sep 11 '18 at 15:37
  • Can you add some motivation behind your solution? – Werner Sep 11 '18 at 16:59
  • To expand on Werner's comment, you've posted ~200 lines of code, but it's not clear which of those lines are necessary for your solution (which unfortunately wasn't all that clear to begin with), and which of those lines are superfluous. To respond to your comment, you can highlight your code and then click {} or type ctrl-k. – Teepeemm Sep 11 '18 at 17:37
  • Thanks. the code %this code redefines the chapter format in table of contents \newlength{\len} \titlecontents{chapter}[1.2em]{\bfseries}%\bfseries {\contentslabel[\large{\chaptername} \NUMBERstringnum{\thecontentslabel}:]{3.6em}\settowidth{\len} {Chapter \NUMBERstringnum{\thecontentslabel}}\hspace*{\len}}%] {\large{\thecontentslabel}\hspace*{-5.1cm}}%\contentslabel[]{} {\hfill\contentspage} – user169363 Sep 12 '18 at 11:13
  • Thanks. The lines 58 - 62 and 192-195; \newlength{\len} \titlecontents{chapter}[1.2em]{\bfseries}%\bfseries {\contentslabel[\large{\chaptername} \NUMBERstringnum{\thecontentslabel}:]{3.6em}\settowidth{\len} {Chapter \NUMBERstringnum{\thecontentslabel}}\hspace*{\len}}%] {\large{\thecontentslabel}\hspace*{-5.1cm}}%\contentslabel[]{} {\hfill\contentspage} % adds page number of chapters without dots in table of contents while lines 140 to 143 removes page number of chapters in table of contents. – user169363 Sep 12 '18 at 11:36
0

Write this code \addtocontents{toc}{\cftpagenumbersoff{chapter}} before the chapter one and \addtocontents{toc}{\cftpagenumberson{chapter}} before references to get the desired result. Here is a minimal example

\documentclass[a4paper,12pt]{report}
\usepackage{graphicx,amsmath,amsthm} %enumerate% directly loaded from texstudio
\usepackage[left=38.00mm, right=13.00mm, top=25.00mm, bottom=13.00mm]{geometry}
\usepackage{lipsum} % for generating dummy texts
\usepackage{tocloft}  %for table of contents and list of figure formatting
\usepackage{fmtcount} % for textual representation of numbers
\usepackage{etoolbox} % for changing internal parameters of latex
\usepackage{fancyhdr}  % for pagestyles
\usepackage{times}    % for times new roman font
%\usepackage[linktoc=all]{hyperref}   % for link to chapter and section
\usepackage{tikz} % for drawing
%\usepackage{titletoc} %for table of content formatting

%%% this code centred, adjust chapters' distance from the title and convert chapter 1 to chapter one
\makeatletter  
\def\@makechapterhead#1{%
    \vspace*{-60\p@}% default: 50pt % vertical distance between chapter and top of page
    {\parindent \z@ \centering \normalfont% default: \raggedright
        \ifnum \c@secnumdepth >\m@ne
        \huge\bfseries \@chapapp\space \NUMBERstring{chapter}%\the
        \par\nobreak
        \vskip 20\p@% default: 20\p@  % vertical distance between chapter and title below it
        \fi
        \interlinepenalty\@M
        \Huge \bfseries #1\par\nobreak
        \vskip 40\p@
}}
\def\@makeschapterhead#1{%
    \vspace*{-70\p@}% default: 50pt % vertical distance between unnumbered chapter and top of page
    {\parindent \z@ \centering% default: \raggedright
        \normalfont
        \interlinepenalty\@M
        \Huge \bfseries  #1\par\nobreak
        \vskip 40\p@
}}
\makeatother

%% This code rename 1 to CHAPTER ONE in table of contents:
\makeatletter  
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
    \refstepcounter{chapter}%
    \typeout{\@chapapp\space\thechapter.}%
    \addcontentsline{toc}{chapter}%
    {\protect \chaptername~\NUMBERstringnum{\thechapter}:~#1}%
    \else
    \addcontentsline{toc}{chapter}{#1}%
    \fi
    \chaptermark{#1}%
    \addtocontents{lof}{\protect\addvspace{10\p@}}%
    \addtocontents{lot}{\protect\addvspace{10\p@}}%
    \if@twocolumn
    \@topnewpage[\@makechapterhead{#2}]%
    \else
    \@makechapterhead{#2}%
    \@afterheading
    \fi}
\makeatother

%%% this code changes the names of contets, list of figures,abstract, chapters and references
\renewcommand{\contentsname}{\large{Table of Contents}}
\renewcommand{\listfigurename}{\large{List of Figures}}
\renewcommand{\abstractname}{\large{Abstract}}
\renewcommand{\bibname}{\large{References}}
\renewcommand{\chaptername}{\large{CHAPTER}}
%\renewcommand{\cftchappresnum}{\chaptername~}

%This code centres table of content
\renewcommand{\cfttoctitlefont}{\hspace*{6cm}\large\bfseries}
%\renewcommand{\cfttoctitlefont}{\hfill\large\bfseries}
\renewcommand{\cftaftertoctitle}{\hfill}

%This code centres list of figure
\renewcommand{\cftloftitlefont}{\hfill\large\bfseries}
\renewcommand{\cftafterloftitle}{\hfill}

\linespread{1.8}

% this code for list of tables with figure, cation and page.
\renewcommand{\cftafterloftitle}{\hfill{}
    \\[\baselineskip]\mbox{\textbf{Figure}}\hspace*{6cm}{\textbf{Caption}}\hfill{\normalfont \textbf{Page}}}

%this code removes the references label
\makeatletter
\renewcommand\@biblabel[1]{}
\makeatother


\begin{document}
\titlepage
    \pagenumbering{roman}   

%\phantomsection    
\addcontentsline{toc}{chapter}{\numberline{}Title Page}
\chapter*{Title}
\thispagestyle{empty}
\newpage

%\phantomsection
\addcontentsline{toc}{chapter}{\numberline{}Certification}

    \chapter*{\large{Certification}}

\newpage
%\phantomsection
\addcontentsline{toc}{chapter}{\numberline{}Dedication}

    \chapter*{\large{Dedication}}


\newpage
%\phantomsection
\addcontentsline{toc}{chapter}{\numberline{}Acknowledgements}

\chapter*{\large{Acknowledgements}}

\newpage

%\phantomsection
\addcontentsline{toc}{chapter}{\numberline{}Table of Contents}
\setlength{\cftbeforetoctitleskip}{-2.5cm} %to control vertical spacing
\tableofcontents
\clearpage
%\phantomsection
\addcontentsline{toc}{chapter}{\numberline{}List of Figures}
\setlength{\cftbeforeloftitleskip}{-2.5cm} %to control vertical spacing
\listoffigures 
\clearpage
%\phantomsection
\addcontentsline{toc}{chapter}{\numberline{}Abstract}
\chapter*{\large{Abstract}}

\newpage
%\phantomsection    
\addcontentsline{toc}{chapter}{\numberline{}Nomenclatures}

    \chapter*{\large{Nomenclatures}}

\newpage  
\pagenumbering{arabic}
\addtocontents{toc}{\cftpagenumbersoff{chapter}}
\chapter{\large{INTRODUCTION}}

\fancyhf{}
%\fancyhead[C]{\thepage}
\pagestyle{fancy}
\fancypagestyle{plain} 
\fancyhf{}
\fancyhead[C]{\thepage}
\renewcommand{\headrulewidth}{0pt}
%\pagenumbering{arabic}
\setcounter{page}{1}
\section{Introduction}

\section{Section 1}
\subsection{Subsection 1}
\subsection{Subsection 2}

\section{Section 2} 

\chapter{\large{LITERATURE REVIEW}}
\section{Section 1}

\newpage
%\phantomsection
\addtocontents{toc}{\cftpagenumberson{chapter}}
\addcontentsline{toc}{chapter}{\numberline{} REFERENCES}
\thispagestyle{empty}
\begin{thebibliography}{99}
\bibitem{1} First reference
\bibitem{2} Second reference
\end{thebibliography}

\end{document}
  • This is a better code than the one I posted before it. I hope somebody will help me put it in proper format. – user169363 Oct 5 '18 at 11:02
  • Thank you Stefan Pinnow for putting my code in proper format for this page. I am very grateful. I hope it will be useful for others. – user169363 Oct 26 '18 at 12:33

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.