# Problem with \tableofcontents in revtex4-1

While I was answering List of Figures/Tables - eliminate dots? I found some strange behaviour; this document:

\documentclass[aps,pra,reprint]{revtex4-1}

\begin{document}

\listoffigures
\listoftables
\tableofcontents

\section{Test Section}
\subsection{Test Subsection}
\section{Another Test Section}

\end{document}


produces the expected result:

but as soon as \tableofcontents is placed before the other two lists, as in

\documentclass[aps,pra,reprint]{revtex4-1}

\begin{document}

\tableofcontents
\listoffigures
\listoftables

\section{Test Section}
\subsection{Test Subsection}
\section{Another Test Section}

\end{document}


the resulting document shows some problems in the ToC; the section numbers and their titles overlap:

What is the cause of this problem and how can it be corrected?

-

## Problem

The problem is that there is generic code for all toc-generating commands which expands to something like (see the definition of \@starttoc in ltxutil.dtx):

\toc@pre      % Loads previously saved \tocmax@section etc. and sets
% \tocdim@section etc. to a fixes small value (5pt)
...
\@input{\jobname.#1} % Formats the toc, lof etc. but only
% computes \tocdim@section etc. if the
% .toc is loaded
...
\toc@post     % Saves \tocdim@section etc. as \tocmax@section in .aux


The \tocdim@section values are only computed properly in the actual table of contents (the lof and lot do not contain section lines). If a lof of lot appears after the toc, then \toc@pre resets the values and \toc@post saves the reset values, which then get read and used next time.

The only way this code works properly as written is to make sure that the \tableofcontents command comes last.

## Quick Fix

Disable the resetting and writing of the various \tocmax@* information after the \tableofcontents is typeset:

\tableofcontents

\makeatletter
\let\toc@pre\relax
\let\toc@post\relax
\makeatother

\listoffigures
\listoftables

-
I have reported this as a bug to the revtex developers. –  mforbes Dec 7 '11 at 4:12