[Tex/LaTex] Table of Contents within Appendix

appendicestable of contents

My Minimum Working Example:

\documentclass{article}

\usepackage{appendix}

\begin{document}

\section{My First Section}

\section{My Second Section}

\begin{appendices}

\section*{My First Appendix}

Here I want something like:

\noindent My First Subsection ........... 1

\noindent My Second Subsection ........ 1

\subsection*{My First Subsection}

\subsection*{My Second Subsection}

\section*{My Second Appendix}

\end{appendices}

\end{document}

The result:

enter image description here

So basically, I want a table of contents within My First Appendix, only containing references to the subsections appearing in this Appendix.

Best Answer

Below I present another two options.

Here's one possibility using the titletoc package; simply use \DoToC whereever you want to generate the partial ToC:

\documentclass{article}
\usepackage{appendix}
\usepackage{titletoc}

\newcommand\DoToC{%
  \startcontents
  \printcontents{}{2}{\textbf{Contents}\vskip3pt\hrule\vskip5pt}
  \vskip3pt\hrule\vskip5pt
}

\begin{document}

\section{My First Section}
\section{My Second Section}

\begin{appendices}
\section{My First Appendix}
\DoToC
\subsection{My First Subsection}
\subsection{My Second Subsection}

\section{My Second Appendix}
\DoToC
\subsection{My First Subsection}
\subsection{My Second Subsection}
\end{appendices}

\end{document}

enter image description here

Here's now one possibility using the etoc package; simply use \localtableofcontents whereever you want to generate the partial ToC:

\documentclass{article}
\usepackage{appendix}
\usepackage{etoc}

\begin{document}

\section{My First Section}
\section{My Second Section}

\begin{appendices}
\section{My First Appendix}
\localtableofcontents
\subsection{My First Subsection}
\subsection{My Second Subsection}

\section{My Second Appendix}
\localtableofcontents
\subsection{My First Subsection}
\subsection{My Second Subsection}
\end{appendices}

\end{document}

enter image description here