Document ClassesProblem with ToC in custom Class

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
startingalaxy
Posts: 5
Joined: Thu Jul 19, 2012 9:06 pm

Problem with ToC in custom Class

Post by startingalaxy »

I am having a very strange problem with \tableofcontents. Here is my code.

Code: Select all

\documentclass[12pt]{thesis}  %12pt is larger than 11pt
\setcounter{tocdepth}{2}
\setcounter{secnumdepth}{2}

\begin{document}
\tableofcontents
\chapter{Introduction}
\section{sec 1}
\subsection{subsec 1}
\subsection{subsec 2}
\subsubsection{temp1}
\subsubsection{temp2}
\end{document}
The problem is that when I set tocdepth to 1, then ToC displays currently up to the depth of \section, but when I give it 2, it goes all the way to \subsubsection while it should only display until \subsection.

"thesis" is something that has been provided to me by my school. Strangely when I use the standard "report.cls", problem does not occur, but when I looked at both class files, the part that defines \tablefocontents seems same. Any help would be highly appreciated.

I am uploading the "thesis" class file for you to see.
Thanks!
Attachments
thesis.cls
(22.77 KiB) Downloaded 381 times
Last edited by localghost on Thu Jul 19, 2012 9:48 pm, edited 3 times in total.

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

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Problem with ToC in custom Class

Post by cgnieder »

This is a bug in the class. Lines 619--623 read (comment added by me):

Code: Select all

\newcommand*\l@section{\@dottedtocline{1}{1.5em}{2.3em}}
\newcommand*\l@subsection{\@dottedtocline{2}{3.8em}{3.2em}}
\newcommand*\l@subsubsection{\@dottedtocline{2}{7.0em}{4.1em}}% <= here is the bug!
\newcommand*\l@paragraph{\@dottedtocline{4}{10em}{5em}}
\newcommand*\l@subparagraph{\@dottedtocline{5}{12em}{6em}}
The first argument to \@dottedtocline in the marked line should be a 3 instead of a 2.

PS: I like your comment

Code: Select all

%12pt is larger than 11pt
;)

Regards
site moderator & package author
startingalaxy
Posts: 5
Joined: Thu Jul 19, 2012 9:06 pm

Re: Problem with ToC in custom Class

Post by startingalaxy »

Great! solved....
Cant thank you enough!!
startingalaxy
Posts: 5
Joined: Thu Jul 19, 2012 9:06 pm

Problem with ToC in custom Class

Post by startingalaxy »

Hi,
I have one more follow up question. I actually want to restrict the appendix ToC to depth 0, and for that I do the following:

Code: Select all

\begin{document}
\tableofcontents %(required, lower-case Roman)
\newpage
\listoftables %(if present, lower-case Roman)
\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
\include{09conclusion}
\appendixpage
\include{AppendixA}
\end{document}
But when I do this, Apendix in ToC is restricted to depth 0 as desired, but my "List of Tables" goes away, i.e. it is just an empty page. Could you be able to tell why that would be?

also strangely, when I do not add \appendixpage, appendix is not restricted to 0 depth with "List of Tables" still disappeared.
Thanks in advance.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Problem with ToC in custom Class

Post by cgnieder »

Could you please provide a proper Infominimal working example (beginning with \documentclass) and all needed packages to recreate your problem? For example I cannot include 09conclusion.tex as I don't have the file (and it is probably not needed for the example at all) and I don't want to guess where \appendixpage is defined.

Regards
site moderator & package author
startingalaxy
Posts: 5
Joined: Thu Jul 19, 2012 9:06 pm

Problem with ToC in custom Class

Post by startingalaxy »

Hi,
Here is the minimal working example. This time without my custom class. In order to recreate the example, do the following:
1. In the following code, you will see that the depth of the second chapter is 1 (until section) and "List of tables" is displayed correctly.
2. Now set the tocdepth in line \addtocontents{toc}{\protect\setcounter{tocdepth}{1}} to 0, and see that as desired, depth of the chapter 2 reduced to 0, but at the same time, "List of the tables" also disppears.

Code: Select all


\documentclass[12pt]{report}  %12pt is larger than 11pt
\setcounter{tocdepth}{2}
\begin{document}
\tableofcontents
\listoftables
\chapter{My chapter}
\section{My section}
\begin{table}
\begin{tabular}{|c|c|}
\hline 
a & b \\ 
\hline 
c & d \\ 
\hline 
\end{tabular} 
\caption{My table}
\end{table}
\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
\chapter{Introduction}
\section{sec 1}
\end{document}
Thanks
startingalaxy
Posts: 5
Joined: Thu Jul 19, 2012 9:06 pm

Problem with ToC in custom Class

Post by startingalaxy »

Never mind, It is resolved. I just had to include \setcounter{tocdepth}{2} right before \tableofcontents. Thanks anyways.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Problem with ToC in custom Class

Post by cgnieder »

Well, you're writing \setcounter{tocdepth}{0} to the TOC. That means that from that line in the TOC on the value is 0 in the whole document until you change it again.

Either add the following line after the chapter with depth 0

Code: Select all

\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
or if this only concerns the last chapter of the document add

Code: Select all

\setcounter{tocdepth}{2}
directly after \tableofcontents:

Code: Select all

\documentclass[12pt]{report}  %12pt is larger than 11pt
\setcounter{tocdepth}{2}
\begin{document}
\tableofcontents
\listoftables
\chapter{My chapter}
\section{My section}
\begin{table}
\begin{tabular}{|c|c|}
\hline
a & b \\
\hline
c & d \\
\hline
\end{tabular}
\caption{My table}
\end{table}
\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
\chapter{Introduction}
\section{sec 1}
\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
\end{document}
Regards
site moderator & package author
Post Reply