[Tex/LaTex] Modifying formatting of Table of Contents heading

chaptersdocument-classestable of contentsthesis

I am finishing up my Master's thesis and need to modify the formatting of the heading for the Table of Contents (TOC). My university's guidelines require "TABLE OF CONTENTS" to appear in all caps in the top-center of the page.

I am working with a modified version of the ucthesis.cls template. The original template defines the TOC as:

[Code A]

\def\tableofcontents{\@restonecolfalse
  \if@twocolumn\@restonecoltrue\onecolumn\fi
  \chapter*{\contentsname
       \@mkboth{\uppercase{\contentsname}}{\uppercase{\contentsname}}
  }%
  {\ssp\@starttoc{toc}}\if@restonecol\twocolumn\fi}

My workaround to make "TABLE OF CONTENTS" appear correctly has been to rewrite this part of the template as:

[Code B]

\def\tableofcontents{\@restonecolfalse
  \if@twocolumn\@restonecoltrue\onecolumn\fi
  \clearpage
  \begin{center}   
        \MakeUppercase{\contentsname}
  \end{center}
  {\ssp\@starttoc{toc}}\if@restonecol\twocolumn\fi}

This works as expected, but removing the \chapter*{} line has the side effect of removing indentations before section and subsection numbers in the TOC, as defined by the following lines of code included in the ucthesis.cls template

\def\l@section{\@dottedtocline{1}{1.5em}{2.3em}}
\def\l@subsection{\@dottedtocline{2}{3.8em}{3.2em}}

Below are the outputs from code snippets A and B, respectively.

Incorrect TOC header, correct indentation

Correct TOC header, incorrect indentation

I don't have much experience with LaTeX templates or macros and have found it difficult to dig up some documentation on what things like \@mkboth do. If anyone can shed some light on why the TOC needs to be included as a chapter and how I might be able to change the appearance of the header, it would be greatly appreciated–Thanks!

Best Answer

Quick fix:

Redefine \contentsname

\renewcommand{\contentsname}{TABLE OF CONTENTS}

and apply a patch to \@makeschapterhead locally only for the ToC, that means, when you have to issue \tableofcontents, write the lines:

{\makeatletter
\patchcmd{\@makeschapterhead}
  {\raggedright}
  {\centering}
  {}
  {}
\tableofcontents
\makeatother}

MWE:

\documentclass{ucthesis}

\usepackage{etoolbox}

\renewcommand{\contentsname}{TABLE OF CONTENTS}

\begin{document}

{\makeatletter
\patchcmd{\@makeschapterhead}
  {\raggedright}
  {\centering}
  {}
  {}
\tableofcontents
\makeatother}

\listoffigures
\listoftables
\chapter{Test}
\section{A section}

\end{document} 

Output:

enter image description here

Related Question