GeneralAdding "Chapter" and "Appendix" to ToC

LaTeX specific issues not fitting into one of the other forums of this category.
chelos
Posts: 6
Joined: Mon Nov 17, 2008 10:30 pm

Adding "Chapter" and "Appendix" to ToC

Post by chelos »

phi wrote:I tested the code, and it works on my system (TeXLive 2007). Do you use exactly the same code?
I got it! For some reason, I still had \tableofcontents{} instead of just \tableofcontents.

Thanks a bunch phi ... I never would have figured this one out on my own. It's great to learn new tricks like this.

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

sivals
Posts: 8
Joined: Mon Jul 27, 2009 6:12 pm

Re: Adding "Chapter" and "Appendix" to ToC

Post by sivals »

Hi

Thank you. i used following commands
\usepackage{tocloft}
\renewcommand{\cftchapfont}{\bfseries}
\renewcommand{\cftchappagefont}{\bfseries}
\renewcommand{\cftchapaftersnum}{:}
\renewcommand{\cftchapnumwidth}{7em}
\makeatletter
\newcommand*\updatechaptername{%
\addtocontents{toc}{\protect\renewcommand*\protect\cftchappresnum{\@chapapp\ }}
}
\makeatother


i got result. but section and susection are not aligned properly. any one can help me to solve this.

my output is something like

chapter 1: Introduction........1
1.1 introduction................1
but i want
chapter 1: Introduction........1
.......... 1.1 intro...........1

Thank you
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Adding "Chapter" and "Appendix" to ToC

Post by gmedina »

Hi,

you can use something like the following:

Code: Select all

\documentclass{book}
\usepackage{tocloft}

\renewcommand{\cftchappresnum}{\MakeUppercase{\chaptername}~}
\renewcommand{\cftchapaftersnumb}{\qquad}
\renewcommand{\cftchapfont}{\bfseries}
\renewcommand{\cftchappagefont}{\bfseries}
\renewcommand{\cftchapaftersnum}{:}
\setlength{\cftchapnumwidth}{7em}
\renewcommand{\cftsecindent}{6.1em}
\setlength{\cftsecnumwidth}{3.3em}
\renewcommand{\cftsubsecindent}{6.1em}
\setlength{\cftsubsecnumwidth}{3.3em}

\begin{document}
\tableofcontents

\chapter{Test chapter one}
\section{Test section one one}
\section{Test section one two}
\subsection{Test subsection one two one}
\subsection{Test section one two two}
\section{Test section one three}

\end{document}
Refer to the tocloft documentation for further information.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
sivals
Posts: 8
Joined: Mon Jul 27, 2009 6:12 pm

Re: Adding "Chapter" and "Appendix" to ToC

Post by sivals »

Hi gmedina,

Thank you veru much for your help. the code worked nice for me. i hope we can move section little bit further. some thing like this

Chapter 1. Introduction
...............1.1 Introduction
please can you tell me suitable command to do this. your help is appreciated.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Adding "Chapter" and "Appendix" to ToC

Post by gmedina »

All you have to do (in the code that I postd before) is to set the appropriate lengths in the second argument in these lines:

Code: Select all

...
\renewcommand{\cftsecindent}{6.1em}
...
\renewcommand{\cftsubsecindent}{6.1em}
...
1,1,2,3,5,8,13,21,34,55,89,144,233,...
sivals
Posts: 8
Joined: Mon Jul 27, 2009 6:12 pm

Re: Adding "Chapter" and "Appendix" to ToC

Post by sivals »

Hi

Thank you very much for your help.
i have got the fruitful result from this code.
Post Reply