0

I'm using different chapter names in the chapter itself and the table of contents: \chapter[Chapter 1 – Introduction]{Introduction}. I'm also using chapter numbers (\thechapter) in chapter headers as per this recommendation.

There seems to be a conflict with \setcounter{secnumdepth}{0} because the ToC still adds extra chapter numbers:

Extra chapter numbers in table of content

How would I get rid of those extra chapter numbers (e.g. 1 Chapter 1 – Introduction)?

I'm starting to use a lot of custom codes. Here's what it looks like (sorry for the long list of packages):

\documentclass[12pt,openany,hidelinks]{book}

\usepackage[utf8]{inputenc}
\usepackage{fullpage}
\usepackage[left=1in,right=1in,top=1in,bottom=1.2in]{geometry} 
\usepackage{import}
\usepackage{setspace}
\setstretch{1.15}
\usepackage{afterpage}
\usepackage{xcolor}
\usepackage{enumitem}
\usepackage{amsmath}
\usepackage{tabularx,graphicx}
\usepackage{imakeidx}
\usepackage{textcomp}
\usepackage{multicol}
\usepackage{multirow}
\usepackage[labelformat=empty]{caption}
\usepackage{array}
\usepackage{makecell}
\usepackage{etoolbox}
\usepackage{float}
\usepackage{hyperref}
\usepackage{changepage}
\urlstyle{rm}
\usepackage{fancyhdr}
\usepackage{url}
\usepackage{xurl}
\graphicspath{ {./images/} }
\indexsetup{othercode=\small}
\makeindex[program=makeindex,columns=2,intoc=false,options={-s index-style.ist}]
\usepackage{enumitem,amssymb}
\usepackage{titlesec}
\usepackage{totcount}
\usepackage{tocloft}


% Chapter Headers

\regtotcounter{chapter}
\titleformat{\chapter}[hang]
  {\raggedright\rmfamily\bfseries\fontsize{62}{56}\selectfont}
  {\LARGE\rmfamily\mdseries
   % magic number 25pt
   \raisebox{25pt}{\smash{\parbox[t]{4em}{\thechapter\\/\\26}}}}
  {0pt}{}
\titlespacing*{\chapter}{0pt}{50pt}{40pt}[140pt]

% Title Sizes

\titlespacing*{\chapter}{0pt}{0pt}{140pt} % Redundant but needed

\titleformat{\section}[display]
  {\huge\bfseries}{}{0pt}{\fontsize{22}{24}\selectfont}
\titlespacing*{\section}{0pt}{17pt}{20pt}

\titleformat{\subsection}[display]
  {\huge\bfseries}{}{0pt}{\fontsize{22}{28}\selectfont}
\titlespacing*{\subsection}{0pt}{20pt}{20pt}

% Table of Contents Config

\newcount\cnta
\cftsetpnumwidth{0pt}
\renewcommand\cftsecpagefont {\ttfamily\global\cnta}
\renewcommand\cftsecafterpnum {%
  \makebox[0pt][l]%
     {\kern-\dimexpr\linewidth\relax\makebox[2em][l]{\ttfamily\normalsize\the\cnta}}%
}
\renewcommand{\cftpartpagefont}{\ttfamily\global\cnta}
\renewcommand\cftpartafterpnum {%
  \makebox[0pt][l]%
     {\kern-\dimexpr\linewidth\relax\makebox[2em][l]{\ttfamily\large\the\cnta}}%
\vskip14pt
}
\renewcommand{\cftchappagefont}{\ttfamily\bfseries\global\cnta}
\renewcommand\cftchapafterpnum {%
  \makebox[0pt][l]%
     {\kern-\dimexpr\linewidth\relax\makebox[2em][l]{\large\bfseries\the\cnta}}%
\vskip7pt
}

\renewcommand{\cftdot}{}
\setcounter{tocdepth}{1}
\setcounter{secnumdepth}{0}
\renewcommand{\contentsname}{Table of Contents}

\renewcommand{\cftpartfont}{\ttfamily\large} 
\renewcommand{\cftchapfont}{\rmfamily\large\bfseries}

\setlength{\cftpartindent}{4em}
\setlength{\cftchapindent}{4em}
\setlength{\cftsecindent}{4em}

\begin{document}

% Table of Contents
\tableofcontents{}

\addcontentsline{toc}{part}{Inception}
\chapter[Chapter 1 – Introduction]{Introduction}
\section{Section A}
\section{Section B}
\section{Section C}

\chapter[Chapter 2 – Middle]{Middle}
\section{Section A}
\section{Section B}
\section{Section C}

\chapter[Chapter 3 – Middle]{Conclusion}
\section{Section A}
\section{Section B}
\section{Section C}

\end{document}

2 Answers 2

1

Change redefinition of \ctfchapfont from

\renewcommand{\cftchapfont}{\rmfamily\large\bfseries}

to

\renewcommand{\cftchapfont}{\rmfamily\large\bfseries\renewcommand\numberline[1]{}}

That means, (locally) redefine \numberline for every chapter toc entry, hence the chapter number is hidden from typesetting.

\documentclass[12pt,openany]{book}
\usepackage[left=1in,right=1in,top=1in,bottom=1.2in]{geometry}
\usepackage{titlesec}
\usepackage{totcount}
\usepackage{tocloft}


% Chapter Headers

\regtotcounter{chapter}
\titleformat{\chapter}[hang]
  {\raggedright\rmfamily\bfseries\fontsize{62}{56}\selectfont}
  {\LARGE\rmfamily\mdseries
   % magic number 25pt
   \raisebox{25pt}{\smash{\parbox[t]{4em}{\thechapter\\/\\26}}}}
  {0pt}{}
\titlespacing*{\chapter}{0pt}{50pt}{40pt}[140pt]

% Title Sizes

\titlespacing*{\chapter}{0pt}{0pt}{140pt} % Redundant but needed

\titleformat{\section}[display]
  {\huge\bfseries}{}{0pt}{\fontsize{22}{24}\selectfont}
\titlespacing*{\section}{0pt}{17pt}{20pt}

\titleformat{\subsection}[display]
  {\huge\bfseries}{}{0pt}{\fontsize{22}{28}\selectfont}
\titlespacing*{\subsection}{0pt}{20pt}{20pt}

% Table of Contents Config

\newcount\cnta
\cftsetpnumwidth{0pt}
\renewcommand\cftsecpagefont {\ttfamily\global\cnta}
\renewcommand\cftsecafterpnum {%
  \makebox[0pt][l]%
     {\kern-\dimexpr\linewidth\relax\makebox[2em][l]{\ttfamily\normalsize\the\cnta}}%
}
\renewcommand{\cftpartpagefont}{\ttfamily\global\cnta}
\renewcommand\cftpartafterpnum {%
  \makebox[0pt][l]%
     {\kern-\dimexpr\linewidth\relax\makebox[2em][l]{\ttfamily\large\the\cnta}}%
\vskip14pt
}
\renewcommand{\cftchappagefont}{\ttfamily\bfseries\global\cnta}
\renewcommand\cftchapafterpnum {%
  \makebox[0pt][l]%
     {\kern-\dimexpr\linewidth\relax\makebox[2em][l]{\large\bfseries\the\cnta}}%
\vskip7pt
}

\renewcommand{\cftdot}{}
\setcounter{tocdepth}{1}
\setcounter{secnumdepth}{0}
\renewcommand{\contentsname}{Table of Contents}

\renewcommand{\cftpartfont}{\ttfamily\large} 
\renewcommand{\cftchapfont}{\rmfamily\large\bfseries\renewcommand\numberline[1]{}}

\setlength{\cftpartindent}{4em}
\setlength{\cftchapindent}{4em}
\setlength{\cftsecindent}{4em}

\begin{document}

% Table of Contents
\tableofcontents

\addcontentsline{toc}{part}{Inception}
\chapter[Chapter 1 – Introduction]{Introduction}
\section{Section A}
\section{Section B}
\section{Section C}

\chapter[Chapter 2 – Middle]{Middle}
\section{Section A}
\section{Section B}
\section{Section C}

\chapter[Chapter 3 – Middle]{Conclusion}
\section{Section A}
\section{Section B}
\section{Section C}

\end{document}

enter image description here

3
  • I tried that, but chapter numbers then disappear in the chapters themselves. It doesn't seem to like this: \regtotcounter{chapter} \titleformat{\chapter}[hang] {\raggedright\rmfamily\bfseries\fontsize{62}{56}\selectfont} {\LARGE\rmfamily\mdseries % magic number 25pt \raisebox{25pt}{\smash{\parbox[t]{4em}{\thechapter\\/\\26}}}} {0pt}{} \titlespacing*{\chapter}{0pt}{50pt}{40pt}[140pt]
    – egarbugli
    Aug 5, 2020 at 20:29
  • @egarbugli Hi, I updated my answer. Hope it helps you this time. Aug 5, 2020 at 22:34
  • Worked perfectly. Thanks so much! :-)
    – egarbugli
    Aug 6, 2020 at 7:34
0

You are adding the **Chapter 1 - ** to the ToC yourself.

The \chapter macro takes one optional and one required argument. These are:

\chapter[toc+header title]{title}

so your \chapter[Chapter 1 - Introduction]{Introduction} puts Chapter 1 - Introduction into the ToC and header, plus the chapter number and puts Chapter 1 followed on another line by Introduction in the body of the document.

So, don't use the optional argument.

However, if you need different entries in the ToC, header, and document the memoir class (a superset of book) provides two optional arguments for \chapter and other division headings as:

\chapter[toc-title][header-title]{title}

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.