GeneralCalling \@starttoc

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
jarnhus
Posts: 3
Joined: Sun Nov 01, 2009 4:35 pm

Calling \@starttoc

Post by jarnhus »

Hello,

I encountered a slight problem, when I started playing around with the look of Table of Contents.

The simple example I tried was

Code: Select all

\documentclass[a4paper,12pt]{report}
\def\tableofcontents{\section*{\centering Contents}\@starttoc{toc}}
\begin{document}
\tableofcontents
\chapter{A}
\chapter{B}
\section{B1}
\end{document}
I get the error

!You can't use '\spacefactor' in vertical mode.
\@->\spacefactor
\@m
l.4 \tableofcontents


Can anyone point me in the direction of my screw up.

Cheers!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Calling \@starttoc

Post by gmedina »

Hi,

the command \@starttoc contains the special character @; to be able to manipulate commands containing this character in the preamble of your document, you need to enclose the relevant part using \makeatletter...\makeatother.

Try the following:

Code: Select all

\documentclass[a4paper,12pt]{report}
\makeatletter
\def\tableofcontents{\section*{\centering Contents}\@starttoc{toc}}
\makeatother
\begin{document}
\tableofcontents
\chapter{A}
\chapter{B}
\section{B1}
\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
jarnhus
Posts: 3
Joined: Sun Nov 01, 2009 4:35 pm

Re: Calling \@starttoc

Post by jarnhus »

That did the trick... Thank you very much!!
Post Reply