[Tex/LaTex] Adding sections to list of appendices by using macros

appendicestable of contents

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

enter image description here

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.
\LoadClass[letterpaper,12pt,oneside]{report}


\RequirePackage{setspace}

\RequirePackage[printonlyused]{acronym}

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


%% ---- TABLE OF CONTENTS ----------------------------------------------
% This sets the formatting for chapter entries in the table of contents.
\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}

% These lines set the spacing for other table of contents entries.
\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}}

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

% This sets the formatting of the table of contents.
\renewcommand*{\tableofcontents}{%
 % Move to new page.
 \newpage %
 % Add a pdf anchor.
 \phantomsection %
 % Add a bookmark manually for the table of contents.
 \pdfbookmark[0]{Table of Contents}{\thepage} %
 % Use front page styling.
 \frntpg %
 % Larger upper margin for first page of table
  \begin{minipage}{0.8\textwidth} \vspace{1in} \end{minipage} \\ %
 % Add the title
 \centerline{\large\bf TABLE OF CONTENTS} %
 % Add some space after the title.
 \vspace{2ex} %
 % Start the automatic table of contents features.
 \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 %
 % Add this page to the table of contents.
 \phantomsection\addcontentsline{toc}{chapter}{List of Appendices} %
 % 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} \\ %
 % Add the title
 \centerline{\large\bf LIST OF APPENDICES} %
 % Add some space after the title.
 \vspace{1ex} %
 % Start the automatic table of contents features.
 \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} %
 % Add a pdf anchor.
 \phantomsection %
 % Add the page to the table of contents.
 \addcontentsline{toc}{chapter}{Appendices}
 % Stop adding sections to the table of contents.
 \addtocontents{toc}{\setcounter{tocdepth}{1}} %
 % Header for appendices.
 \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 %
 % Add a bookmark manually.
 \pdfbookmark[0]{#1}{#2} %
 % Add to the list of appendices rather than toc.
 \addcontentsline{loa}{chapter}{\protect\numberline{\thechapter}#1} %
 % Save the chapter number.
 \chaptermark{#1} %
}

%
%% ---- LINKS ----------------------------------------------------------
% This loads a package that allows extra colors for links.
\RequirePackage[usenames,dvipsnames]{color}
\RequirePackage[pagebackref=true]{hyperref}

 \hypersetup{ %
  colorlinks=true, %
  pdfstartview={FitH}, %
  citecolor=DarkGreen, %
  linkcolor=Black, %
  urlcolor=Blue %
 }



%% ---- INITIALIZATION -------------------------------------------------
% Commands to be placed after \begin{document}
\AtBeginDocument{ %
 % Insert the table of contents.
 \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}

Please instruct me on how I can modify to add sections.


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.

enter image description here

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.
\LoadClass[letterpaper,12pt,oneside]{report}


\RequirePackage{setspace}

\RequirePackage[printonlyused]{acronym}

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


%% ---- TABLE OF CONTENTS ----------------------------------------------
% This sets the formatting for chapter entries in the table of contents.
\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}

% These lines set the spacing for other table of contents entries.
\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}}

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

% This sets the formatting of the table of contents.
\renewcommand*{\tableofcontents}{%
 % Move to new page.
 \newpage %
 % Add a pdf anchor.
 \phantomsection %
 % Add a bookmark manually for the table of contents.
 \pdfbookmark[0]{Table of Contents}{\thepage} %
 % Use front page styling.
 \frntpg %
 % Larger upper margin for first page of table
  \begin{minipage}{0.8\textwidth} \vspace{1in} \end{minipage} \\ %
 % Add the title
 \centerline{\large\bf TABLE OF CONTENTS} %
 % Add some space after the title.
 \vspace{2ex} %
 % Start the automatic table of contents features.
 \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 %
 % Add this page to the table of contents.
 \phantomsection\addcontentsline{toc}{chapter}{List of Appendices} %
 % 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} \\ %
 % Add the title
 \centerline{\large\bf LIST OF APPENDICES} %
 % Add some space after the title.
 \vspace{1ex} %
 % Start the automatic table of contents features.
 \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} %
 % Add a pdf anchor.
 \phantomsection %
 % Add the page to the table of contents.
 \addcontentsline{toc}{chapter}{Appendices}
 % Stop adding sections to the table of contents.
 %\addtocontents{toc}{\setcounter{tocdepth}{1}} %
 % Header for appendices.
 \renewcommand{\@chapapp}{APPENDIX} %
 % Renew the chapter and section labels.
 \let\@chapter\@chapter@appendix %
 \let\oldaddcontentsline\addcontentsline% Copy \addcontentsline
 % Force \addcontentsline to ALWAYS add to List of Appendices
 \renewcommand{\addcontentsline}[1]{\oldaddcontentsline{loa}}%
}

% 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 %
 % Add a bookmark manually.
 \pdfbookmark[0]{#1}{#2} %
 % Add to the list of appendices rather than toc.
 \addcontentsline{loa}{chapter}{\protect\numberline{\thechapter}#1} %
 % 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 %
 % Add this page to the table of contents.
 \phantomsection\addcontentsline{toc}{chapter}{List of Tables} %
 % Use front page styling.
 \frntpg %
 % Larger upper margin for first page of table
  \begin{minipage}{0.8\textwidth} \vspace{1in} \end{minipage} \\ %
 % Add the title
 \centerline{\large\bf LIST OF TABLES} %
 % Add some space after the title.
 \vspace{1ex} %
 % Start the automatic table of contents features.
 \begin{singlespace} %
  \@starttoc{lot}\if@restonecol\twocolumn\fi %
 \end{singlespace} %
}

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

% Change the bibliography header.
\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 %
 % Add to table of contents.
 \addcontentsline{toc}{chapter}{Bibliography} %
 % Load the bibliography.
 \@tex@bibliography{#1} %
}
%
%% ---- LINKS ----------------------------------------------------------
% This loads a package that allows extra colors for links.
\RequirePackage[usenames,dvipsnames]{color}
\RequirePackage[pagebackref=true]{hyperref}
 \hypersetup{%
  colorlinks=true, %
  pdfstartview={FitH}, %
  citecolor=DarkGreen, %
  linkcolor=Black, %
  urlcolor=Blue %
 }

%% ---- INITIALIZATION -------------------------------------------------
% Commands to be placed after \begin{document}
\AtBeginDocument{ %
 % Insert the table of contents.
 \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}

Best Answer

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}{1}} %

Changing the number here should give some more control over the depth of your 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;

Table of Appendices