Next: \addtocontents, Up: Table of contents etc. [Contents][Index]
\addcontentsline
Synopsis:
\addcontentsline{ext}{unit}{text}
Add an entry to the file specified by ext. Usually ext is
one of toc
for the table of contents, lof
for the list of
figures, or lot
for the list of tables.
The following will result in an ‘Appendices’ line in the table of contents.
\addcontentsline{toc}{section}{\protect\textbf{Appendices}}
It will appear at the same indentation level as the sections, will be in boldface, and will be assigned the page number associated with the point where it appears in the input file.
The \addcontentsline
command writes information to the file
root-name.ext. It writes that information as the
text of the command
\contentsline{unit}{text}{num}
, where
num
is the current value of counter unit
. The
most common case is the table of contents and there num is the
page number of the first page of unit.
This command is invoked by the sectioning commands \chapter
,
etc., and also by \caption
inside a float environment. But it is
also used by authors. For example, in a book to have the preface
unnumbered, you may use the starred \chapter*
. But that does not
put in table of contents information, so you can enter it manually, as
here.
\chapter*{Preface} \addcontentsline{toc}{chapter}{\protect\numberline{}Preface}
In the .toc file LaTeX will put the line \contentsline
{chapter}{\numberline {}Preface}{3}
; note the page number
‘3’.
All of the arguments for \addcontentsline
are required.
Typically one of the strings toc
for the table of contents,
lof
for the list of figures, or lot
for the list of
tables. The filename extension of the information file.
A string that depends on the value of the ext argument:
toc
For the table of contents, this is the name of a sectional unit:
part
, chapter
, section
, subsection
, etc.
lof
For the list of figures: figure
.
lot
For the list of tables: table
.
The text of the entry. You must \protect
any commands that are
fragile (see \protect).
The \addcontentsline
command has an interaction with
\include
(see \include & \includeonly). If you use them at
the same level, as with
\addcontentsline{...}{...}{...}\include{...}
then lines
in the table of contents can come out in the wrong order. The solution
is to move \addcontentsline
into the file being included.
If you use a unit that LaTeX does not recognize, as here
\addcontentsline{toc}{setcion}{\protect\textbf{Appendices}}
then you don’t get an error but the formatting in the table of contents will not make sense.