Text FormattingTable of Content: add "Chapter" in ToC

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
isix
Posts: 5
Joined: Wed Feb 11, 2009 8:03 pm

Table of Content: add "Chapter" in ToC

Post by isix »

Good day!

I have the following issue regarding the way Table of Content looks:

This is what the table of contents pages currently looks like:

Table of Contents
1 Introduction ....... Page #
1.1 Really Introducing ....... Page #
2 The Data ....... Page #
2.1 About the Data ....... Page #


But I wouldlike to have the following style:

Table of Contents
Chapter 1 Introduction ....... Page #
1.1 Really Introducing ....... Page #
Chapter 2 The Data ....... Page #
2.1 About the Data ....... Page #


That means I would like to have the word "Chapter" printed in front of the chapter index in the Table of Contents. By the way, the word "Chapter" should not appear in front of the indexes of the sections and the subsections.

Is this do-able? How can I achieve this?

Isix

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Re: Table of Content: add "Chapter" in ToC

Post by daleif »

depends on your document class. The memoir class supports this out of the box by placing

\renewcommand\cftchaptername{\chaptername~}

in the preamble

If you are not able to use memoir, then tocloft may be able to do this, but it has been a while since I had a look at that package.
s.david
Posts: 43
Joined: Thu Sep 10, 2009 5:22 pm

Table of Content: add "Chapter" in ToC

Post by s.david »

daleif wrote:depends on your document class. The memoir class supports this out of the box by placing

\renewcommand\cftchaptername{\chaptername~}

in the preamble

If you are not able to use memoir, then tocloft may be able to do this, but it has been a while since I had a look at that package.
how to make this looks like:
Chapter One: instead of Chapter 1?
daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Table of Content: add "Chapter" in ToC

Post by daleif »

In the ToC or in the text?

In the ToC you have have to do some hacking

Code: Select all

\documentclass[a4paper]{memoir}
\let\oldchapternumberline\chapternumberline
\renewcommand\chapternumberline[1]{%
  \oldchapternumberline{\numtoName{#1}}}
\renewcommand\cftchaptername{\chaptername~}
\addtolength\cftchapternumwidth{1em}
\begin{document}
\tableofcontents*
\chapter{test}
\end{document}
note that this is not a general solution, as it does not take appendices into account (i.e. chapter numbering that are not numbers)
s.david
Posts: 43
Joined: Thu Sep 10, 2009 5:22 pm

Table of Content: add "Chapter" in ToC

Post by s.david »

daleif wrote:In the ToC or in the text?

In the ToC you have have to do some hacking

Code: Select all

\documentclass[a4paper]{memoir}
\let\oldchapternumberline\chapternumberline
\renewcommand\chapternumberline[1]{%
  \oldchapternumberline{\numtoName{#1}}}
\renewcommand\cftchaptername{\chaptername~}
\addtolength\cftchapternumwidth{1em}
\begin{document}
\tableofcontents*
\chapter{test}
\end{document}
note that this is not a general solution, as it does not take appendices into account (i.e. chapter numbering that are not numbers)
Thanks. But how to make the chapter name directly follows the chapter number. For example, in my case, the ToC appears like this:

Chapter One:....Name1
Chapter Two:....Name2
Chapter Three: Name3

The dots are used just to fill the spaces

I want this to look like this:

Chapter One: Name1
Chapter Two: Name2
Chapter Three: Name3

Thanks in dvance
daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Table of Content: add "Chapter" in ToC

Post by daleif »

Then you will have to change \chapternumberline

Code: Select all

\makeatletter
\renewcommand\chapternumberline[1]{%
   \@chapapp@head\@cftbsnum \numtoName{#1}\@cftasnum~}
\renewcommand\cftchaptername{\chaptername~}
\makeatother
would be enough
s.david
Posts: 43
Joined: Thu Sep 10, 2009 5:22 pm

Table of Content: add "Chapter" in ToC

Post by s.david »

daleif wrote:Then you will have to change \chapternumberline

Code: Select all

\makeatletter
\renewcommand\chapternumberline[1]{%
   \@chapapp@head\@cftbsnum \numtoName{#1}\@cftasnum~}
\renewcommand\cftchaptername{\chaptername~}
\makeatother
would be enough
Ok, now it is working just fine.

Thank you very much.

Regards
isix
Posts: 5
Joined: Wed Feb 11, 2009 8:03 pm

Table of Content: add "Chapter" in ToC

Post by isix »

daleif, according to your first reply I did:

Code: Select all

\documentclass[a4paper]{memoir}

\renewcommand\cftchaptername{\chaptername~}

\begin{document}
\tableofcontents*
\chapter{Intro}
	\section{History}
\chapter{Theory}
	\section{The Equation}
\chapter{Hypothesis}
	\section{Our Claim}
\chapter{Analysis}
	\section{Tne Work}
\chapter{Results}
	\section{Suprises}
\chapter{Conclusion}
	\section{Next Stuff}
\end{document}
Which results in the error message

Code: Select all

[LaTeX] test-toc-formating.tex => test-toc-formating.dvi (latex)
[LaTeX] finished with exit status 1
./test-toc-formating.tex:3:\cftchaptername undefined. \renewcommand\cftchaptername
[LaTeX] 1 error, 0 warnings, 0 badboxes
Where am I going wrong? If I include the package tocloft (which I have) as in

Code: Select all

\usepackage{tocloft}
then it gets worse, because now the errors would be about 25, refering to the file tocloft.sty.

Isix6
daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Re: Table of Content: add "Chapter" in ToC

Post by daleif »

Which version of memoir are you using?

try adding \listfiles before \documentclass, and then look in the log file.

You seem to be using an old memoir
isix
Posts: 5
Joined: Wed Feb 11, 2009 8:03 pm

Table of Content: add "Chapter" in ToC

Post by isix »

I get:

Code: Select all

 *File List*
  memoir.cls    2004/04/05 v1.61 configurable document class
   mem10.clo    2002/07/27 v0.2 memoir class 10pt size option
mempatch.sty    2005/02/01 v3.5 Patches for memoir class v1.61
 ***********
Could my memoir be old?
Post Reply