[Tex/LaTex] Display \chaptername in table of contents

chapterstable of contentstocloft

I'm looking for something to resolve the problem that has been metioned at How do I get \chaptername to appear in the table of contents? and Table of Contents with “Chapter” and per-chapter “Appendix” threads.

Those is exactly what I'm looking for. But I've got error when as soon as using

\usepackage{tocloft}

And here is the error messenge:

! LaTeX Error: Command \c@lofdepth already defined.
Or name \end… illegal, see p.192 of the manual.

See the LaTeX manual or LaTeX Companion for explanation.
Type H for immediate help.
l.597 \newcounter{lofdepth} \setcounter{lofdepth}{1}

Please tell me what is that error! And how to fix?

My .cls file contain:

\renewcommand\tableofcontents{
\btypeout{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}
}

And because there is error occured when I've tried using the tocloft package. So I have used the following code block:

\makeatletter
\let\@@l@chapter\l@chapter
\def\l@chapter#1{\@@l@chapter{\chaptername\ #1}}
\makeatother

But the result is not as well as my wish. It's look like this:

Chapter List of tables
…..
Chapter List of figures
Chapter 1 Introduction
The chapter 1 contents table.
….
Chapter A Examples

But what I wanna is something like this:

List of tables
List of figures

Chapter 1 Introduction

Chapter 2 And so on…
Appendix A

Anyone can give me some suggestion? Thanks avandce!

Best Answer

The error you are getting comes from loading the tocloft and subfigure packages simultaneously, as the following example swhows:

\documentclass{article}
\usepackage{tocloft}
\usepackage{subfigure}

\begin{document}

test

\end{document}

As soon as one processes this document, the following error shows up:

! LaTeX Error: Command \c@lofdepth already defined.
               Or name \end... illegal, see p.192 of the manual.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.124 \newcounter{lofdepth}

The problem is that both packages define the counters lofdepth and lotdepth. To prevent the error, simply load tocloft with the subfigure option; i.e., load the packages like this:

\documentclass{article}
\usepackage[subfigure]{tocloft} 
\usepackage{subfigure} 

\begin{document}

test

\end{document}

By the way, sufigure is an obsolete package and shouldn't be used anymore; subfig or subcaption are valid alternatives