[Tex/LaTex] Customize Appendix package

appendiceskoma-scripttable of contents

I need to customize my Appendix but can not figure out how.

I need:

  1. Entry in my Main ToC at the beginning of the document generated with \tableofcontents
  2. Change the Name of Appendices displayed in the ToC to the German "Anhang"
  3. Insert the Appendix after my References
    • Titel Page with "Anhang"
    • ToC showing each Chapter/section of the Appendix and page number

What would be the best way to do this using the Appendix package?

Thanks!

EDIT: I need to edit the MWE so that the entries that currently show up in the Main ToC do not show any more, only the Entry: "Anhang". The first Page after the appendix Titel Page should be a separate ToC that shows the entries of the appendix and the page number.

Here is a MWE:

\documentclass[a4paper,12pt,twoside,ngerman]{scrartcl} 
\usepackage{setspace} 
\usepackage{lmodern} 
\usepackage[ngerman]{babel} 
\usepackage[toc,title,page]{appendix} % Anhang 

\renewcommand{\appendixpagename}{\appendixname}
\renewcommand{\appendixtocname}{\appendixname}

\begin{document} 
\tableofcontents %Inhaltsverzeichnis 
\newpage 
\section{Section}
Test 123
\newpage 
\subsection{SubSection 1} 
Test 123
\newpage 
\begin{appendices} 
\section{Test}

TEST 123

\section{Test 2}

TEST 123


\section{Test 3}

TEST 123


\end{appendices} 
\end{document}

Best Answer

With a KOMA-Script class you can use the automatically loaded package tocbasic to define an additional ToC.

\documentclass[12pt,twoside,ngerman]{scrartcl} 
\usepackage{babel}

%%% see: https://komascript.de/comment/5578#comment-5578 (Markus Kohm)
\DeclareNewTOC[%
  owner=\jobname,
  listname={Inhalt des Anhangs},% Titel des Verzeichnisses
]{atoc}% Dateierweiterung (a=appendix, toc=table of contents)

\makeatletter
\newcommand*{\useappendixtoc}{%
  \renewcommand*{\ext@toc}{atoc}%
  \scr@ifundefinedorrelax{hypersetup}{}{% damit es auch ohne hyperref funktioniert
    \hypersetup{bookmarkstype=atoc}%
  }%
}
\ifundefinedorrelax{ext@toc}{%
  \newcommand*{\ext@toc}{toc}
  \renewcommand{\addtocentrydefault}[3]{%
    \expandafter\tocbasic@addxcontentsline\expandafter{\ext@toc}{#1}{#2}{#3}%
  }
}{}
\makeatother
%%%

\usepackage{xpatch}
\xapptocmd\appendix{%
  \cleardoublepage
  \vspace*{\fill}
  \addpart{\appendixname}
  \thispagestyle{empty}
  \vfill\vfill
  \clearpage
  \useappendixtoc
  \listofatocs
}{}{\PatchFailed}

\renewcommand\raggedpart{\centering}
\setkomafont{partentry}{\usekomafont{sectionentry}}

\usepackage{blindtext}
\begin{document} 
\tableofcontents 
\Blinddocument
\Blinddocument

\appendix
\blinddocument
\blinddocument
\end{document}

enter image description here

enter image description here

If you switch to scrreprt you can use:

\documentclass[12pt,twoside,ngerman]{scrreprt} 
\usepackage{babel}

%%% see: https://komascript.de/comment/5578#comment-5578 (Markus Kohm)
\DeclareNewTOC[%
  owner=\jobname,
  listname={Inhalt des Anhangs},% Titel des Verzeichnisses
]{atoc}% Dateierweiterung (a=appendix, toc=table of contents)

\makeatletter
\newcommand*{\useappendixtoc}{%
  \renewcommand*{\ext@toc}{atoc}%
  \scr@ifundefinedorrelax{hypersetup}{}{% damit es auch ohne hyperref funktioniert
    \hypersetup{bookmarkstype=atoc}%
  }%
}
\ifundefinedorrelax{ext@toc}{%
  \newcommand*{\ext@toc}{toc}
  \renewcommand{\addtocentrydefault}[3]{%
    \expandafter\tocbasic@addxcontentsline\expandafter{\ext@toc}{#1}{#2}{#3}%
  }
}{}
\makeatother
%%%

\usepackage{xpatch}
\xapptocmd\appendix{
  \cleardoublepage
  \addpart{\appendixname}
  \useappendixtoc
  \listofatocs
}{}{\PatchFailed}

\renewcommand\partpagestyle{empty}
\setkomafont{partentry}{\usekomafont{chapterentry}}

\usepackage{blindtext}
\begin{document} 
\tableofcontents 
\Blinddocument
\Blinddocument

\appendix
\blinddocument
\blinddocument
\end{document}

Dots between all TOC entries and their page numbers:

If you want to add dots between the chapter entries and their page numbers in all TOCs insert the following line in your preambel:

\RedeclareSectionCommands[toclinefill=\TOCLineLeaderFill]{chapter,part}

If you want to add these dots only in the appendix TOC use either

\xapptocmd\appendix{
  \cleardoublepage
  \addpart{\appendixname}
  \RedeclareSectionCommand[toclinefill=\TOCLineLeaderFill]{chapter}% <- added
  \useappendixtoc
  \listofatocs
}{}{\PatchFailed}

or

\xapptocmd\appendix{
  \cleardoublepage
  \addpart{\appendixname}
  \KOMAoptions{toc=chapterentrywithdots}% <- added
  \useappendixtoc
  \listofatocs
}{}{\PatchFailed}