you are using amsbook
. admittedly, the implementation of tables of contents is faulty. leaving aside the reasons for that (fixing it is something that is in the list for the next upgrade, which unfortunately hasn't been scheduled yet), the ams has a package that will allow you to adjust the format to something more suitable.
since the package is not publicly posted, please send a message to tech-support@ams.org
requesting it.
the package is not what we would call "industrial strength", and the methods used are not how the problems should be fixed when incorporated directly into amsbook
. for these reasons, it is made available only on request.
Some weird code-golfing with xparse
and a slightly (;-)) modified \section
command -- do not use \subsection
there!
I just added a 4th optional argument to \section
, which is a *
, indicating that this should be an appendix section, going right here, not at the end of the document. (well, a chapter appendix then)
It will break if another 'normal' \section
will follow.
All is reset if the next \chapter
comes into action.
And there is some warning by hyperref
, but the links work.
\documentclass{book}
\usepackage{xpatch}
\usepackage{xparse}
\usepackage{blindtext}
\newcounter{appsection}[chapter]
\usepackage{hyperref}
\makeatletter
\let\latex@section\section
\let\latex@thesection\thesection
\RenewDocumentCommand{\section}{soms}{%
\IfBooleanTF{#1}{%
\latex@section*{#4}
}{%
\IfBooleanT{#4}{%
\ifnumgreater{\value{appsection}}{0}{%
}{%
\setcounter{section}{0}%
\renewcommand{\thesection}{\thechapter.\Alph{appsection}}%
\renewcommand{\theHsection}{\thechapter.\Alph{appsection}}%
}
\stepcounter{appsection}%
}%
\IfValueTF{#2}{%
\latex@section[#2]{#3}%
}{%
\latex@section{#3}%
}%
}%
}
% Restore the section number format.
\xpretocmd{\chapter}{\renewcommand{\thesection}{\latex@thesection}}{}{}
\makeatother
\begin{document}
\tableofcontents
\chapter{First}
\section{First section}
\section{Second section}
\section{First appendix}*
\chapter{Second}
\blindtext[10]
\section{First section}
\section{Second section}
\clearpage
\section{First appendix}*
\blindtext[10]
\clearpage
\section{Second appendix}*
\blindtext[10]
\chapter{Third}
\blindtext[10]
\section{First section}
\section{Second section}
\section{Third section}
\section{Fourth section}
\clearpage
\section{First appendix}*
\blindtext[10]
\clearpage
\section{Second appendix}*
\blindtext[10]
\section{Third appendix}*
\blindtext[10]
\end{document}
Update Improved interface and preventing sections to be added after some section has been declared as appendix
section. It automatically adds a Appendix
and a clearpage. subsections
etc. work as expected as well as references.
The macro call is \section![toc title]{body title}
if is meant to be an appendix section at the end of the chapter. If !
is omitted, the standard command is used.
\documentclass{book}
\usepackage{xpatch}
\usepackage{xparse}
\usepackage{blindtext}
\newcounter{appsection}[chapter]
\usepackage[bookmarksopen=true,bookmarksopenlevel=5]{hyperref}
\makeatletter
\newif\ifappsectionclearpage
\appsectionclearpagetrue
\newif\ifappsection
\appsectionfalse
\let\latex@section\section
\let\latex@thesection\thesection
\RenewDocumentCommand{\section}{st!om}{%
\IfBooleanTF{#1}{%
\latex@section*{#4}
}{%
\IfBooleanTF{#2}{%
\appsectiontrue%
\ifnumgreater{\value{appsection}}{0}{%
}{%
\setcounter{section}{0}%
\renewcommand{\thesection}{\thechapter.\Alph{appsection}}%
\renewcommand{\theHsection}{\thechapter.\arabic{appsection}}%
}
\stepcounter{appsection}%
\ifappsectionclearpage
\clearpage
\fi
\IfValueTF{#3}{%
\latex@section[#3]{\appendixname~#4}%
}{%
\latex@section{\appendixname~#4}%
}%
}{%
\ifappsection
%% Nothing in here!
\else
\IfValueTF{#3}{%
\latex@section[#3]{#4}%
}{%
\latex@section{#4}%
}%
\fi
}%
}%
}
\xpretocmd{\chapter}{\renewcommand{\thesection}{\latex@thesection}\protect\appsectionfalse}{}{}
\makeatother
\begin{document}
\tableofcontents
\chapter{First}
\section{First section}
\section{Second section}
\section!{First appendix}
In \ref{thirdapp:thirdchap} we will see that
\chapter{Second}
\blindtext[10]
\section{First section}
\section{Second section}
\clearpage
\section!{First appendix}
\blindtext[10]
\clearpage
\section!{Second appendix}
\blindtext[10]
\chapter{Third}
\blindtext[10]
\section{First section}
\section{Second section}
\section{Third section}
\section{Fourth section}
\clearpage
\section!{First appendix}
\blindtext[10]
\clearpage
\section!{Second appendix}
\subsection{First}
\blindtext[10]
\section!{Third appendix} \label{thirdapp:thirdchap}
\blindtext[10]
\section{Fifth section} % Will be ignored
\end{document}
Best Answer
You can insert part, chapter or any other references in a table of contents, list of figures or list of tables with
\addcontentsline{ext}{type}{text}
whereext
is the extension of auxiliar file (usually toc, lof, lot),type
specifies type of contents andtext
what you want to be shown in the list. Here you have a simple example.The result is
The package tocloft allows you to define or change the format of a table of contents but I've never used it. You can read its introduction and will learn how ToC works in LaTeX.
EDIT: You can avoid typing twice chapter names and part names if you declare your own commands. Look at the example
\mypart
command contains\part
and\addcontentsline
. This way, parts and chapters inlof
will look the same as intoc
.