After changing default chapter notation to Lecture, How do I get it to table of contents? I'm getting only main chapter numbers. But I want my table of content to look like this,

Lecture 1

1.1 Introduction...........3

Lecture 2

2.2 GrahQL.................5

I have attached a M. W. E. below.

\documentclass[12pt,a4paper]{book}
\begin{document}
\tableofcontents
\makeatletter
\renewcommand{\@chapapp}{Lecture}
\makeatother
\chapter{}
\section{Introduction}
\chapter{}
\section{GraphQL}
\end{document}


Use the tocloft package.

% lecturetocprob.tex  SE 569160

\documentclass[12pt,a4paper]{book}
\usepackage{tocloft}
\addtolength{\cftchapnumwidth}{4em}  % more space for number + Lecture
\renewcommand{\cftchappresnum}{Lecture }
\begin{document}
\tableofcontents
\makeatletter
\renewcommand{\@chapapp}{Lecture}
\makeatother
\chapter{}

\section{Introduction}
\chapter{}
\section{GraphQL}

\appendix

\chapter{In appendix}

\end{document}


I have extended your MWE to include an Appendix just to check that that would be OK, even though you are probably not having any appendices.

• Chose this as the answer, because this not only answers my question but also has given how to separate by chapters by small spacing in the toc.
– emil
Nov 14 '20 at 3:36

You can patch \@chapter so it issues \chapternumberline instead of \numberline: then we can define \chapternumberline to do what we prefer.

\documentclass[12pt,a4paper]{book}
\usepackage{etoolbox}
%\usepackage{hyperref}

\renewcommand{\chaptername}{Lecture}
\makeatletter
{\patchcmd{\Hy@org@chapter}}
{\patchcmd{\@chapter}}
{\numberline}{\chapternumberline}{}{}
\newcommand{\chapternumberline}[1]{\chaptername\ #1}
\makeatother

\begin{document}

\tableofcontents

\chapter{}
\section{Introduction}
\chapter{}
\section{GraphQL}

\end{document}


I made the patch working for the cases when hyperref is loaded or not.

Note that the correct command to redefine is \chaptername rather than \@chapapp.

Here's a picture when hyperref is used, showing that the entire entry is a link.

Perhaps this would work:

\documentclass[12pt,a4paper]{book}

\usepackage{titletoc}
\titlecontents*{chapter}[0pt]{}
{\hfill\bfseries\contentspage}

\usepackage{hyperref}

\begin{document}
\tableofcontents
\makeatletter
\renewcommand{\@chapapp}{Lecture}
\makeatother
\chapter{}
\section{Introduction}
\chapter{}
\section{GraphQL}
\end{document}

• This works. kudos! but has a slight edge. hyperef in heading is gone now. Is there any fix to that?
– emil
Nov 1 '20 at 6:31
• @emil Thanks for pointing this out! I've edited my answer to support hyperlinks, check it ~ Nov 1 '20 at 7:03