Theses, Books, Title pagesAdding 'Chapter 1' instead of '1' to the Contents page

Classicthesis, Bachelor and Master thesis, PhD, Doctoral degree
Post Reply
Corned Beef Hash
Posts: 5
Joined: Thu Oct 15, 2015 5:26 pm

Adding 'Chapter 1' instead of '1' to the Contents page

Post by Corned Beef Hash »

My University requires that the chapter and appendix names in the table of contents have 'Chapter' and 'Appendix' before each chapter #. I'm lost as to how to accomplish this, I've read the "LaTeX for Complete Novices" chapter referring to this issue, but am having trouble implementing it with the table of contents commands in this template. Is there a way to revise these commands, or would it be best if I just started over and made a new table of contents?

Code: Select all

\addtocounter{secnumdepth}{1}
\setcounter{tocdepth}{6}
\newcounter{dummy}
\newcommand\addtotoc[1]{
\refstepcounter{dummy}
\addcontentsline{toc}{chapter}{#1}}
\renewcommand\tableofcontents{
\btypeout{Table of Contents}
\addtotoc{Contents}
\begin{spacing}{1}{
    \setlength{\parskip}{1pt}
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\contentsname
        \@mkboth{
           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}
    \@starttoc{toc}
    \if@restonecol\twocolumn\fi
   \cleardoublepage
}\end{spacing}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: Adding 'Chapter 1' instead of '1' to the Contents page

Post by Johannes_B »

Hi there,

one thing i can tell you is that you are using an obsolete version of the template. It got some huge upgrades and you should be able to switch with just a little bit of effort.

How to have the prefix in the toc? I'll have a loook at that later.
But please, what do you expect to be in a table of contents. I bet you also a requested to have the word figure in your list of figures. What else would you expect there? Socks? Gun powder? Tissues? Sometimes, those university regulations are insane. :-(
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Corned Beef Hash
Posts: 5
Joined: Thu Oct 15, 2015 5:26 pm

Re: Adding 'Chapter 1' instead of '1' to the Contents page

Post by Corned Beef Hash »

Haha, thanks for your condolences! This is the last edit I have to make in the document, so I think I'll stick with this version, unless it would be much easier to switch. I should admit that I am very new to LaTeX, so I might be making some very beginner mistakes. Let me know if there is any other information that I can provide. Thanks for taking a look!
Corned Beef Hash
Posts: 5
Joined: Thu Oct 15, 2015 5:26 pm

Adding 'Chapter 1' instead of '1' to the Contents page

Post by Corned Beef Hash »

Posting my own answer. If you use what 'Lockstep' posted at http://tex.stackexchange.com/questions/ ... ers-in-toc, the .cls file can be left as is, and the code that 'Lockstep' wrote:

Code: Select all

\usepackage{tocloft,calc}
\renewcommand{\cftchappresnum}{\chaptername\space}
\setlength{\cftchapnumwidth}{\widthof{\textbf{Appendix~999~}}}
\makeatletter
\g@addto@macro\appendix{%
  \addtocontents{toc}{%
    \protect\renewcommand{\protect\cftchappresnum}{\appendixname\space}%
  }%
}
Can be pasted into the main.tex file directly before \tableofcontents. The added bonus is that writes in 'Appendix' in addition to 'Chapter'. I know that I am using an older version of the template, so this is probably not applicable to many people, but I thought I'd throw it out there anyway.

Cheers!
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Adding 'Chapter 1' instead of '1' to the Contents page

Post by Stefan Kottwitz »

Thanks for telling us the solution!

A typical LaTeX hack. :-) A final \makeatother would be cleaner, but is not necessary.

Stefan
LaTeX.org admin
mikenass
Posts: 1
Joined: Tue Jan 28, 2020 8:50 pm

Adding 'Chapter 1' instead of '1' to the Contents page

Post by mikenass »

Corned Beef Hash wrote:Posting my own answer. If you use what 'Lockstep' posted at http://tex.stackexchange.com/questions/ ... ers-in-toc, the .cls file can be left as is, and the code that 'Lockstep' wrote:

Code: Select all

\usepackage{tocloft,calc}
\renewcommand{\cftchappresnum}{\chaptername\space}
\setlength{\cftchapnumwidth}{\widthof{\textbf{Appendix~999~}}}
\makeatletter
\g@addto@macro\appendix{%
  \addtocontents{toc}{%
    \protect\renewcommand{\protect\cftchappresnum}{\appendixname\space}%
  }%
}
Can be pasted into the main.tex file directly before \tableofcontents. The added bonus is that writes in 'Appendix' in addition to 'Chapter'. I know that I am using an older version of the template, so this is probably not applicable to many people, but I thought I'd throw it out there anyway.

Cheers!

Hello I used this code I can now see the word chapter followed by the number like the following

Chapter 1 Introduction.....................................................1

I need help in two things:
1) How I can add the colon after the number, means to have
Chapter 1: Introduction.....................................................1
2) The code I have is limited the number of chapters only to five, so the sixth chapter is appearing like Appendix
how I can fix this (i.e. increasing number of chapters

Thank you for your help!
Post Reply