# Adding sections to list of appendices by using macros

I have a thesis template. It has the list of appendices as a separate page of toc.

But I would like to add sections into this list of appendices, like,

A Chapter One of Appendix
A.1 Section One
A.2 Section Two
B Chapter Two of Appendix
A.1 Section One
A.2 Section Two


Here is the the template "style.cls" I used. Sorry it is a little bit messy. I extracted it from a big template file.

%% This passes any other options on to the 'report' class.
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}%
\typeout{Unknown option: passing \CurrentOption"
option on to the standard LaTeX report class.}}
% This command tells LaTeX to simply process the class options.
\ProcessOptions
%
%% This control structure calls the standard LaTeX report.cls class.
%% The base font size should be 10pt unless using the submit option.

\RequirePackage{setspace}

\RequirePackage[printonlyused]{acronym}

\newcommand*{\frntpg}{ %
% Check the number of columns.
\newpage
\thispagestyle{plain}
}

\renewcommand*\l@chapter[2]{ %
% First add some vertical space.
\vskip 1ex plus 1pt minus 1pt
% Format the spacing and use dots between title and number.
\@dottedtocline{1}{0em}{1.0em} %
% This sets the formatting for the chapter name and page number.
{\textbf{#1}}{\textbf{#2}} %
% Add some space below, too.
\vskip 1ex}

\renewcommand*{\l@section}{\@dottedtocline{2}{2.5em}{2em}}
\renewcommand*{\l@subsection}{\@dottedtocline{3}{5.0em}{2.8em}}
\renewcommand*{\l@subsubsection}{\@dottedtocline{4}{7.5em}{3.5em}}

\setcounter{tocdepth}{3}
% Number of subsection layers to allow in document
\setcounter{secnumdepth}{3}

\renewcommand*{\tableofcontents}{%
% Move to new page.
\newpage %
\phantomsection %
% Use front page styling.
\frntpg %
% Larger upper margin for first page of table
\begin{minipage}{0.8\textwidth} \vspace{1in} \end{minipage} \\ %
% Add some space after the title.
\vspace{2ex} %
\begin{singlespace} %
\@starttoc{toc}\if@restonecol\twocolumn\fi %
\end{singlespace} %
}

%% ---- LIST OF APPENDICES ---------------------------------------------
% This sets the formatting for appendices in the list.
\newcommand*{\l@appendix}{\@dottedtocline{1}{0em}{2.5em}}

% This sets the formatting of the list of appendices page.
\newcommand*{\listofappendices}{%
% Move to new page.
\newpage %
% Anchor for pdf
\phantomsection %
% Use front page styling.
\frntpg %
% Larger upper margin for first page of table (thesis only)
\begin{minipage}{0.8\textwidth} \vspace{1in} \end{minipage} \\ %
\centerline{\large\bf LIST OF APPENDICES} %
% Add some space after the title.
\vspace{1ex} %
\begin{singlespace} %
\@starttoc{loa}\if@restonecol\twocolumn\fi %
\end{singlespace} %
}

% Renew the command that starts the appendices.
\renewcommand{\appendix}{ %
% Move to new page.
\clearpage %
% Renew the counters.
\renewcommand*{\thechapter}{\Alph{chapter}} %
% Start over the chapter counter.
\setcounter{chapter}{0} %
\phantomsection %
\renewcommand{\@chapapp}{APPENDIX} %
% Renew the chapter and section labels.
\let\@chapter\@chapter@appendix %
}

% Make a special chapter command for appendices.
\def\@chapter@appendix[#1]#2{ %
% Increase the chapter letter.
\refstepcounter{chapter} %
% Print a line to the .log file.
\typeout{\@chapapp\space\thechapter.} %
% Hopefully this works.
\phantomsection %
\pdfbookmark[0]{#1}{#2} %
% Add to the list of appendices rather than toc.
% Save the chapter number.
\chaptermark{#1} %
}

%
\RequirePackage[usenames,dvipsnames]{color}
\RequirePackage[pagebackref=true]{hyperref}

\hypersetup{ %
pdfstartview={FitH}, %
citecolor=DarkGreen, %
urlcolor=Blue %
}

%% ---- INITIALIZATION -------------------------------------------------
% Commands to be placed after \begin{document}
\AtBeginDocument{ %
\tableofcontents %
% Insert the list of appendices.
\listofappendices
\newpage %
}


And here is the testing tex:

\documentclass{style}

%% DOCUMENT AREA
\begin{document}

\chapter{First Chapter}

\chapter{Second Chapter}

\section{First Section}

\section{Second Section}

\subsection{First Subsection}

\subsection{Second Subsection}

\subsection{Third Subsection}

\subsection{Fourth Subsection}

\subsection{Fifth Subsection}

\section{Third Section}

\subsection{First Subsection}

\subsection{Second Subsection}

\subsection{Third Subsection}

\subsection{Fourth Subsection}

\chapter{Third Chapter}

\section{First Section}

\section{Second Section}

\appendix
\chapter{First Chapter of Appendices}

\section{First Section of Appendices}

\section{Second Section of Appendices}

\chapter{Second Chapter of Appendices}

\section{First Section of Appendices}

\section{Second Section of Appendices}

\chapter{Third Chapter of Appendices}

\end{document}


A follow-up question: I modified the code following instruction provided by @Werner. Thanks! If I have bibliography, it will also appear in the LoA now. Also figures and tables in appendices also appear in LoA, which I would like them to be in LoF and LoT respectively.

Style.cls :

%% This passes any other options on to the 'report' class.
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}%
\typeout{Unknown option: passing \CurrentOption"
option on to the standard LaTeX report class.}}
% This command tells LaTeX to simply process the class options.
\ProcessOptions
%
%% This control structure calls the standard LaTeX report.cls class.
%% The base font size should be 10pt unless using the submit option.

\RequirePackage{setspace}

\RequirePackage[printonlyused]{acronym}

\newcommand*{\frntpg}{ %
% Check the number of columns.
\newpage
\thispagestyle{plain}
}

\renewcommand*\l@chapter[2]{ %
% First add some vertical space.
\vskip 1ex plus 1pt minus 1pt
% Format the spacing and use dots between title and number.
\@dottedtocline{1}{0em}{1.0em} %
% This sets the formatting for the chapter name and page number.
{\textbf{#1}}{\textbf{#2}} %
% Add some space below, too.
\vskip 1ex}

\renewcommand*{\l@section}{\@dottedtocline{2}{2.5em}{2em}}
\renewcommand*{\l@subsection}{\@dottedtocline{3}{5.0em}{2.8em}}
\renewcommand*{\l@subsubsection}{\@dottedtocline{4}{7.5em}{3.5em}}

\setcounter{tocdepth}{3}
% Number of subsection layers to allow in document
\setcounter{secnumdepth}{3}

\renewcommand*{\tableofcontents}{%
% Move to new page.
\newpage %
\phantomsection %
% Use front page styling.
\frntpg %
% Larger upper margin for first page of table
\begin{minipage}{0.8\textwidth} \vspace{1in} \end{minipage} \\ %
% Add some space after the title.
\vspace{2ex} %
\begin{singlespace} %
\@starttoc{toc}\if@restonecol\twocolumn\fi %
\end{singlespace} %
}

%% ---- LIST OF APPENDICES ---------------------------------------------
% This sets the formatting for appendices in the list.
\newcommand*{\l@appendix}{\@dottedtocline{1}{0em}{2.5em}}

% This sets the formatting of the list of appendices page.
\newcommand*{\listofappendices}{%
% Move to new page.
\newpage %
% Anchor for pdf
\phantomsection %
% Use front page styling.
\frntpg %
% Larger upper margin for first page of table (thesis only)
\begin{minipage}{0.8\textwidth} \vspace{1in} \end{minipage} \\ %
\centerline{\large\bf LIST OF APPENDICES} %
% Add some space after the title.
\vspace{1ex} %
\begin{singlespace} %
\@starttoc{loa}\if@restonecol\twocolumn\fi %
\end{singlespace} %
}

% Renew the command that starts the appendices.
\renewcommand{\appendix}{ %
% Move to new page.
\clearpage %
% Renew the counters.
\renewcommand*{\thechapter}{\Alph{chapter}} %
% Start over the chapter counter.
\setcounter{chapter}{0} %
\phantomsection %
\renewcommand{\@chapapp}{APPENDIX} %
% Renew the chapter and section labels.
\let\@chapter\@chapter@appendix %
}

% Make a special chapter command for appendices.
\def\@chapter@appendix[#1]#2{ %
% Increase the chapter letter.
\refstepcounter{chapter} %
% Print a line to the .log file.
\typeout{\@chapapp\space\thechapter.} %
% Hopefully this works.
\phantomsection %
\pdfbookmark[0]{#1}{#2} %
% Add to the list of appendices rather than toc.
% Save the chapter number.
\chaptermark{#1} %
}

%% ---- LIST OF TABLES -------------------------------------------------
% This sets the format for the table entries.
\renewcommand*{\l@table}{\@dottedtocline{1}{0em}{2.5em}}

% This sets the formatting of the list of tables page.
\renewcommand*{\listoftables}{%
% Move to new page.
\newpage %
% Use front page styling.
\frntpg %
% Larger upper margin for first page of table
\begin{minipage}{0.8\textwidth} \vspace{1in} \end{minipage} \\ %
\centerline{\large\bf LIST OF TABLES} %
% Add some space after the title.
\vspace{1ex} %
\begin{singlespace} %
\@starttoc{lot}\if@restonecol\twocolumn\fi %
\end{singlespace} %
}

%% ---- BIBLIOGRAPHY ---------------------------------------------------
% Save the original bibliography command.
\let\@tex@bibliography\bibliography

\renewcommand*{\bibname}{\centerline{\large BIBLIOGRAPHY}}

% Create a new command for the bibliography.
\renewcommand*{\bibliography}[1]{ %
% Switch to single spacing
\singlespacing %
% Move to new page.
\clearpage %
% Create a pdf anchor.
\phantomsection %
\@tex@bibliography{#1} %
}
%
\RequirePackage[usenames,dvipsnames]{color}
\RequirePackage[pagebackref=true]{hyperref}
\hypersetup{%
pdfstartview={FitH}, %
citecolor=DarkGreen, %
urlcolor=Blue %
}

%% ---- INITIALIZATION -------------------------------------------------
% Commands to be placed after \begin{document}
\AtBeginDocument{ %
\tableofcontents %
\listoftables
% Insert the list of appendices.
\listofappendices
\newpage %
}


tex:

\documentclass{style}

%% DOCUMENT AREA
\begin{document}

\chapter{First Chapter}

\chapter{Second Chapter}

\section{First Section}

\section{Second Section}

\subsection{First Subsection}

\subsection{Second Subsection}

\subsection{Third Subsection}

\subsection{Fourth Subsection}

\subsection{Fifth Subsection}

\section{Third Section}

\subsection{First Subsection}

\subsection{Second Subsection}

\subsection{Third Subsection}

\subsection{Fourth Subsection}

\chapter{Third Chapter}

\begin{table}[!hbt]
\centering
\caption{Dimensions.}
\footnotesize
\begin{tabular}{lr}
\hline
Length & 152.4 mm \\
Width &  12.7 mm\\
Thickness &  3.0 mm\\
\hline
\end{tabular}
\end{table}

\section{First Section}

\section{Second Section}

\appendix
\chapter{First Chapter of Appendices}

\section{First Section of Appendices}

\section{Second Section of Appendices}

\chapter{Second Chapter of Appendices}

\section{First Section of Appendices}

\section{Second Section of Appendices}

\begin{table}[!hbt]
\centering
\caption{Dimensions.}
\footnotesize
\begin{tabular}{lr}
\hline
Length & 152.4 mm \\
Width &  12.7 mm\\
Thickness &  3.0 mm\\
\hline
\end{tabular}
\end{table}

\chapter{Third Chapter of Appendices}

\begin{table}[!hbt]
\centering
\caption{Dimensions.}
\footnotesize
\begin{tabular}{lr}
\hline
Length & 152.4 mm \\
Width &  12.7 mm\\
Thickness &  3.0 mm\\
\hline
\end{tabular}
\end{table}

\bibliographystyle{aiaa}
% Give this command the relative path to the .bib file.
\bibliography{tex.bib}
\end{document}

• What \documentclass are you using? Please also provide a link to it so we can at least replicate your current usage. – Werner Nov 22 '16 at 2:55
• @Werner Thanks for the reminder. I have uploaded an example. – kyokoxie Nov 22 '16 at 6:40

Regarding your macro, I believe this is the section that is stopping the section titles from being shown;

% Stop adding sections to the table of contents.


\addtocontents{toc}{\setcounter{tocdepth}{2}}


Will give appendix chapter and section titles.

A MWE example of your .tex file would help further.

You should not require that macro as it appears to be causing you formatting problems that you do not want, the code below should give you the output that you desire (though any subsection titles will also be enclosed though \subsection*{#} can alleviate this problem);

\documentclass[10pt]{book}

\begin{document}

\tableofcontents

\appendix

\chapter{Appendix 1}
\section{Appendix 1 Section 1}
\subsection{Appendix 1 Subsection 1}

\section{Appendix 2 Section 2}
\subsection{Appendix 2 Subsection 1}

\end{document}


Which gives;

• Thanks. This comment is desired because we don't want appendix chapters and sections shown in toc. I would like to show appendix chapers as well as appendix sections in a separation list of appendics. – kyokoxie Nov 22 '16 at 6:45

At the end of your definition of \appendix, we want to change the way elements are written to the ToC. In fact, we don't want them written to the ToC, but to the LoA (List of Appendices) instead. we can force this by adding this bit of code at the end of the current definition:

\let\oldaddcontentsline\addcontentsline% Copy \addcontentsline


The above copies the original definition of \addcontentsline and overrides it to be similar to \addcontentsline{loa}, regardless of whether you call it with \addcontentsline{toc} (or something else). This ensures anything that usually would end up in the ToC will now end up in the LoA.

Secondly, since nothing after \appendix will end up in the ToC, we can remove

% Stop adding sections to the table of contents.


since it is now superfluous. The above code actually changes all ToC-related entries at section level and lower to be excluded from ToC-related content. So keeping it in will necessarily avoid printing \sections inside the LoA.

Here is an updated set of instructions for \listofappendices and \appendix:

% This sets the formatting of the list of appendices page.
\newcommand*{\listofappendices}{%
% Move to new page.
\newpage %
% Anchor for pdf
\phantomsection %
% Use front page styling.
\frntpg %
% Larger upper margin for first page of table (thesis only)
\begin{minipage}{0.8\textwidth} \vspace{1in} \end{minipage} \\ %
\centerline{\large\bf LIST OF APPENDICES} %
% Add some space after the title.
\vspace{1ex} %
\begin{singlespace} %
\@starttoc{loa}\if@restonecol\twocolumn\fi %
\end{singlespace} %
}

% Renew the command that starts the appendices.
\renewcommand{\appendix}{ %
% Move to new page.
\clearpage %
% Renew the counters.
\renewcommand*{\thechapter}{\Alph{chapter}} %
% Start over the chapter counter.
\setcounter{chapter}{0} %
\phantomsection %

Your definition of \l@appendix doesn't do anything.