I am looking for a way to create a custom table of content (for my appendices and for annexes) that would be separated from the main table of content and would contain the sections defined for this table as well as a list of all caption inserted. I am not sure this is very clear so this is a representation of what I want :
Main table of content
* standard table of content with both 'Annexes' and 'Appendices' sections. *
List of example %for the sake of example but it would be annexes and appendices
A. Code snippets
A.1. Title of the example containing the first code snippets
A.2. Title of the '' '' '' second '' ''
B. Raw data
B.1. Title of the example containing the first raw data
B.2. Title of the '' '' '' second '' ''
And so on...
When looking for solutions online I found an interesting answer at : Creating a separate list of appendices with tocloft. This makes it possible to have custom tables of content for my document. I 'modified' the code by adding the hyperref package as a way to have pdf bookmarks.
\documentclass[twoside, a4paper]{article} % CHANGED, USED TO BE " \documentclass[toc=flat,numbers=noenddot]{scrartcl}"
\usepackage[english]{babel}% "english" INSTEAD OF "ngerman"
\usepackage{blindtext}
\usepackage{hyperref} % ADDED: To generate hyperlinks in the TOC
\makeatletter
\newcommand{\maintoc}{% main table of contents
\begingroup
@fileswfalse% don't open new ToC file
\renewcommand{\appendixattoc}{% macro for separation of ToC contents
\value{tocdepth}=-10000 % set tocdepth to very small value locally
}%
\tableofcontents% output ToC
\endgroup
}
\newcommand{\appendixtoc}{% table of contents for appendix
\begingroup
\edef@alltocdepth{\the\value{tocdepth}}% save tocdepth
\setcounter{tocdepth}{-10000}% no ToC entries
\renewcommand{\contentsname}{% change ToC name
List of Appendices}% "List of Appendices" INSTEAD OF "Verzeichnis der Anh"ange"
\renewcommand{\appendixattoc}{% macro for separation of ToC contents
\setcounter{tocdepth}{@alltocdepth}% restore tocdepth
}%
\tableofcontents% output ToC
\setcounter{tocdepth}{@alltocdepth}% restore tocdepth
\endgroup
}
\newcommand{\appendixattoc}{% macro for separation of ToC contents
}
\g@addto@macro\appendix{% augment \appendix
% \if@openright\cleardoublepage\else\clearpage\fi% new page; DELETED
\clearpage% new page; ADDED
\addcontentsline{toc}{section}{\appendixname}% entry into main ToC;
% "section" INSTEAD OF "chapter"
\addtocontents{toc}{\protect\appendixattoc}% macro for separation into ToC file
\renewcommand*{\thesection}{Appendix~\Alph{section}}% ADDED
}
\makeatother
\begin{document}
\maintoc
\blinddocument
\appendix
\appendixtoc
\blinddocument
\end{document}
% Note that \maintoc only works if \appendixtoc is also present. Otherwise,
% the ToC will never be updated. If \appendixtoc is removed, one should use
% \tableofcontents instead of \maintoc.
My second step was on making the custom list. For this I amazingly enough found this question : list of newcounter that contains the code necessary to create a custom list that includes the section numbering in its name. I modified the source code slightly to change the format of the caption (centered caption, small caps for the list name, number and title separated with '-' and no period after caption numbering.
% !TEX program = lualatex
\documentclass[twoside, a4paper]{article} % Option [twoside] utile pour la création d'en-tête différentes entre pages paires et impaires
\usepackage{blindtext}
\usepackage{tocloft}
\usepackage{lmodern}
\usepackage{etoolbox}
% SMALL CAPS
% NEW LINE AFTER TITLE AND NUMBER PRECEDED WITH '-'
% CENTER CAPTION
% NO PERIOD AFTER CAPTION NUMBERING
\newcounter{example}[section]
\renewcommand{\theexample}{\arabic{section}.\arabic{example}}
\newenvironment{example}[1][]{%
\refstepcounter{example}%
\ifblank{#1}{}{%
\addcontentsline{exp}{examples}{\protect\numberline{\theexample}#1}%
}%
\par\medskip
\begin{center}
\textsc{Example~\theexample}\ifblank{#1}{}{~--~#1}
\end{center}
}{\medskip}
\newcommand{\listexampletitle}{List of Examples}
\newlistof[section]{examples}{exp}{\listexampletitle}%
\cftsetindents{examples}{1.5em}{3.0em}%
\setlength{\cftexamplesnumwidth}{1.5cm}
\begin{document}
\section{Introduction}%
\listofexamples
\begin{example}[First title]
This is the first example. The counter will be reset at each section.
\end{example}
\
\begin{example}[]
This is the 2nd example, but has no entry to the toc!
\end{example}
\section{A section}
\blindtext[1]
\begin{example}[Another title]
\blindtext[2]
Another example.
\end{example}
\begin{example}[Yet Another title]
\blindtext[3]%
Yet Another example.
\end{example}
\end{document}
However, I must admit I have no idea as to how to 'combine' the two code snippets to create the desired outcome. I do not even know if it is possible.
I am open to all kind of help, thanks.