In order to achieve the OP's request, some aspects must be considered:
Additionally one has to keep in mind
Should it be a command such as \appendix
If this is the case, the restore of settings is a little difficult, but can be done, see below.
- Should it be an environment, say
partappendix
In this case, wrap the settings inside the environments starting and end code sections, best protected by \begingroup
and \endgroup
and restore only the chapter counter in the end code section of the environment.
The principal steps are the same for the setup of the appendix chapter, therefore I defined the \partappendix@@setup
command, which sets the corresponding values and does some redefinitions. This command is called in \appendix
. However, the changes must be reversed at that time when a new true chapter is opened, so I decided, that this is the case, when a new \part
starts, so I let \part
do the reversal of settings to the 'standard' values.
--> Redefine \part
and its fellows.
Note: There must be no true additional \chapter
after \appendix
with this approach.
The usage of
\begin{partappendix}[options]{Appendix Name}
\section{First}
\end[partappendix}
allows additional true \chapter
commands after the environment partappendix
, although this is rather unlikely.
Description of options and arguments to \appendix
and partappendix
environment
- MiniTOC=true/false --> True (default) -> automatically use a
\minitoc
at the start of the appendix
- TOCEntry={} --> Provides a short title as entry to the TOC, otherwise
\Appendixname~\thechapter
is used.
\documentclass[%
bibliography=totoc,
headings=big,
captions=tableheading,
chapterprefix=true% like in standard class "report"
]{scrreprt}
\usepackage[left=2cm,right=2cm,top=2.5cm,bottom=3cm]{geometry}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{minitoc}
\usepackage{setspace}
\usepackage{lmodern}
\newcommand{\mk}[1]{%
}%
\usepackage{etoolbox}%
\usepackage{xkeyval}%
\usepackage{blindtext}%
\usepackage[bookmarksopen=true,bookmarksopenlevel=4]{hyperref}
\usepackage{bookmark}%
\newcounter{resumechaptercounter}%
\newcounter{resumeappendixcounter}%
\makeatletter
% First save some definitions%
\let\LaTeXStandardChapterName\chaptername%
\let\LaTeXStandardTheChapter\thechapter%
\let\LaTeXStandardAppendix\appendix%
\let\LaTeXStandardPart\part%
% Provide the resetting code for some definitions by the renewcommanded \appendix
\newcommand{\part@@pre@mblecode}{%
\renewcommand{\chaptername}{\LaTeXStandardChapterName}%
\renewcommand{\thechapter}{\LaTeXStandardTheChapter}%
\ifnumgreater{\number\value{resumechaptercounter}}{0}{%
\setcounter{chapter}{\number\value{resumechaptercounter}}%
}{}%
}%
%%%% Provide new part code with optional argument
\newcommand{\unstarredpart@opt}[2][]{%
\part@@pre@mblecode%
\LaTeXStandardPart[#1]{#2}%
}%
%%%% Provide new part code without optional argument
\newcommand{\unstarredpart@noopt}[1]{%
\unstarredpart@opt[#1]{#1}%
}%
%%%% Provide a new \part*{} code in order to relax \tableofcontents
\newcommand{\starredpart}[1]{%
\part@@pre@mblecode%
\LaTeXStandardPart*{#1}%
}%
\newcommand{\unstarredpart}{%
\@ifnextchar[{\unstarredpart@opt}{\unstarredpart@noopt}%
}%
%%%% The real redefinition of \part%
%%% Comment it out in order to keep the standard \part behaviour, but
%%% in this case do not use the new \appendix command, only \begin{partappendix} ... \end{partappendix}
\renewcommand{\part}{%
\@ifstar{\starredpart}{\unstarredpart}%
}%
% Create a switch if the minitoc should be enabled in
% an appendix 'chapter' too.
\newtoggle{MiniTOC}%
\define@boolkey{PartAppendix}{MiniTOC}[true]{%
\ifKV@PartAppendix@MiniTOC%
\toggletrue{MiniTOC}%
\else%
\togglefalse{MiniTOC}%
\fi%
}%
\define@key{PartAppendix}{TOCEntry}[]{%
\def\PartAppendixKVMacroTOCEntry{#1}%
}%
%This is the appendix setup, which stores the current
% chapter counter and changes the \thechapter, name etc.
\newcommand{\partappendix@@setup}[2][]{%
\setkeys{PartAppendix}{MiniTOC=true,#1}%
\setcounter{resumechaptercounter}{\number\value{chapter}}% Backup
\renewcommand{\chaptername}{\appendixname}
\setcounter{chapter}{\number\value{resumeappendixcounter}}
\renewcommand{\thechapter}{\Alph{chapter}}
\refstepcounter{resumeappendixcounter}%
\phantomsection%
\ifdef{\PartAppendixKVMacroTOCEntry}{%
\chapter[\PartAppendixKVMacroTOCEntry]{#2}%
}{%
\chapter{#2}%
}%
\iftoggle{MiniTOC}{%
\minitoc
}{}%
}%
% Renew the appendix command
\renewcommand{\appendix}[2][]{%
\partappendix@@setup[#1]{#2}%
}%
\newenvironment{partappendix}[2][]{%
\begingroup%
\appendix[#1]{#2}%
}{%
\endgroup%
\setcounter{chapter}{\number\value{resumechaptercounter}}% Restore the chapter number%
}
\makeatother
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\begin{document}
\dominitoc
\tableofcontents
\addtokomafont{chapterprefix}{\raggedleft}
\addtokomafont{chapter}{\fontsize{30}{38}\selectfont}
\addtokomafont{section}{\huge}
\addtokomafont{subsection}{\Large}
\addtokomafont{subsubsection}{\large}
\renewcommand*{\chapterformat}{%
\mbox{\scalebox{1.5}{\chapappifchapterprefix{\nobreakspace}}%
\scalebox{4}{\color{gray}\thechapter}\enskip}}
\setcounter{chapter}{6}\setcounter{page}{199}
\newpage\setcounter{page}{212}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\part{Introduction}
%%%%%%%%%%%%%%%%%%%%
\chapter{Conclusions}
\dictum[Sun Tzu]{If you know the enemy and you know yourself %\\
you need not fear the results of a hundred battles.}
\minitoc
\section{Summary of Achievements}
\blindtext
\subsection{Papers Submitted}
\blindtext
\subsubsection{I want to go into the TOC}
\blindtext
%%%%%%%%%%%%%%%%%%%% APPENDIX
\begin{partappendix}{Test}
\section{Adding it all in}
Done
\end{partappendix}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\part{Introduction}
%%%%%%%%%%%%%%%%%%%%
\chapter{The no more No MiniTOC Chapter}
\dictum[Sun Tzu]{If you know the enemy and you know yourself %\\
you need not fear the results of a hundred battles.}
\minitoc
\section{Luckily no more unfortunate problems}
This chapter does have a minitoc again
\subsection{Still has a minitoc}
\blindtext
\subsubsection{I want to go into the TOC and there I am}
\blindtext
%%%%%%%%%%%%%%%%%%%%
\chapter{Conclusions}
\dictum[Sun Tzu]{If you know the enemy and you know yourself %\\
you need not fear the results of a hundred battles.}
\minitoc
\section{Summary of Achievements}
\blindtext
\subsection{Papers Submitted}
\blindtext
\begin{partappendix}[TOCEntry={2nd Part Appendix}]{Appendix from second part}
\section{William}
\subsection{Hamlet}%
\subsubsection{Yorick's skull}
\blindtext
\section{Shakespeare}
\end{partappendix}
\appendix[MiniTOC=false]{AnotherAppendix from second part}
\section{Gandalf}
\subsection{Shadowfax}
\section{Frodo}
\subsection{Sting}
\section{Samwise}%
\subsection{Samwise's Uncle}
\subsubsection{Samwise's Art of gardening and cooking rabbits}
\subsubsection{Gollum's distaste of Samwise's cooking arts}%
\part{Dummy part}
\chapter{Dummy chapter}
\appendix{New Appendix from the dummy part}
\section{A dummy appendix section}%
\end{document}
Here are some screen shots of the TOC, chapter 8 starting page with minitoc and of Appendix B
Note Although I have intermixed \appendix
and \begin{partappendix} ...\end{partappendix}
style as a method of demonstration, I would refrain from doing so in production code. Use the environment for 'safety'.
Other note: I did not test for any eventuality so far (who can do this anyway)
Here is a solution with \let\l@chapter\l@section
in .toc
\documentclass[12pt,a4paper,final]{report}
\begin{document}
\tableofcontents
\pagebreak
% Chapters
\chapter{First Chapter}
\chapter{Second Chapter}
\chapter{Third Chapter}
\chapter{Fourth Chapter}
%Appendices
\appendix
\pagebreak % So that \addcontentsline is given the right page number
\addcontentsline{toc}{chapter}{Appendices}
\addtocontents{toc}{\protect\makeatletter}
\addtocontents{toc}{\string\let\string\l@chapter\string\l@section}
\addtocontents{toc}{\protect\makeatother}
\chapter{First Appendix}
\chapter{Second Appendix}
\chapter{Third Appendix}
\end{document}
Best Answer
Appendix chapters are considered chapters as well, specifically because that's what is written to the
.toc
file. To illustrate this, consider the following example:Here's what the
.toc
looks like:Note that each
\contentsline
entry corresponds to an entry in the ToC and they're all consideredchapter
.In order to fix your problem, you can still update
\cftchappresnum
in your preamble, but write an update to this macro as soon as you execute\appendix
. Here's how you can update\appendix
to do this automatically:Now your
.toc
resembles:Each
\contentsline
entry is still achapter
, but\cftchappresnum
was updated at the appropriate time within the.toc
to print anAppendix
prefix for your appendix\chapter
s.