1

I am creating a table of contents (TOC) for multiple appendices in my document using the package tocloft, but in the printed TOC I can only see the names (head) of my appendices and not the sections within each of these appendices. How can I add \section to my TOC?

I am using the (example) code below:

\documentclass{article}
\usepackage{tocloft}
\newcommand{\listappendicesname}{}
\newlistof{appendices}{apc}{\listappendicesname}
\newcommand{\appendices}[1]{\addcontentsline{apc}{appendices}{#1}}
\newcommand{\newappendix}[1]{\section*{#1}\appendices{#1}}
\usepackage[colorlinks=true,urlcolor=black,citecolor=black,linkcolor=black]{hyperref}
\usepackage{lipsum}  

\begin{document}

\section*{Introduction}
\addtocounter{section}{1}

\lipsum[1-2]

\section{Conclusion}

\lipsum[1-2]

\clearpage

\appendix

\setcounter{page}{1}
\setcounter{table}{0}
\setcounter{figure}{0}
\renewcommand{\thetable}{\Alph{section}\arabic{table}}
\renewcommand{\thefigure}{\Alph{section}\arabic{figure}}

\begin{center}
{\large \textbf{Appendices}}
\end{center}


%%% APPENDICES' TABLE OF CONTENTS
\listofappendices

\clearpage 

\newappendix{Appendix I}

\section{Content 1}
\lipsum[1-1]

\section{Content 2}
\lipsum[1-1]

\clearpage

\newappendix{Appendix II}

\section{Content 1}
\lipsum[1-1]

\section{Content 2}
\lipsum[1-1]

\clearpage

\newappendix{Appendix III}

\section{Content 1}
\lipsum[1-1]

\section{Content 2}
\lipsum[1-1]

\end{document}

EDITED:

The TOC I have with my code: TOC I have

The TOC I want: enter image description here

0

1 Answer 1

1

Sections are listed in the document's TOC (\tableofcontents). You have defined a new \listofappendices so you have to get your appendix sections listed in that. Try this:

% tocappendixprob.tex  SE 585983

\documentclass{article}   %%%%% ??????????????????
\usepackage{tocloft}
\newcommand{\listappendicesname}{}
\newlistof{appendices}{apc}{\listappendicesname}
\newcommand{\appendices}[1]{\addcontentsline{apc}{appendices}{#1}}
\newcommand{\newappendix}[1]{\section*{#1}\appendices{#1}}
\usepackage[colorlinks=true,urlcolor=black,citecolor=black,linkcolor=black]{hyperref}

% appendix sections %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\appsec}[1]{\section{#1}%
  \addcontentsline{apc}{section}{\protect\numberline{\thesection}#1}\par}

\usepackage{lipsum}  

\begin{document}

\tableofcontents

\section*{Introduction}
\addtocounter{section}{1}

\lipsum[1-2]

\section{Conclusion}

\lipsum[1-2]

\clearpage

\appendix

\setcounter{page}{1}
\setcounter{table}{0}
\setcounter{figure}{0}
\renewcommand{\thetable}{\Alph{section}\arabic{table}}
\renewcommand{\thefigure}{\Alph{section}\arabic{figure}}

\begin{center}
{\large \textbf{Appendices}}
\end{center}


%%% APPENDICES' TABLE OF CONTENTS
\listofappendices

\clearpage 

\newappendix{Appendix I}

\appsec{Content 1}
\lipsum[1-1]

\appsec{Content 2}
\lipsum[1-1]

\clearpage

\newappendix{Appendix II}

\section{Content 1}
\lipsum[1-1]

\section{Content 2}
\lipsum[1-1]

\clearpage

\newappendix{Appendix III}

\section{Content 1}
\lipsum[1-1]

\section{Content 2}
\lipsum[1-1]

\end{document}

The above produces a warning about a destination with the same identifier, which was also produced with your MWE after I added the \documentclass{article} to get it to compile.

I don't necessarily recommend my \appsec solution as I don't know what you really want; in any case I suggest that you change the format of the Appendix titles in the listing.

Please read again the "New list of ..." section in the tocloft manual. enter image description here

1
  • Peter, you code gets closer. Is it possible to format it as I use in my example? Include the sections below the "Appendix" with the same format but with indentation, and the dots to the page number. Then add some vertical space between the last section of each appendix and the next appendix.
    – Thiago
    Mar 5, 2021 at 21:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .