# Can a chapter style environment be used for appendix formatting?

I have started including appendices in my thesis to collate common information for each separate \part section so as to make the script concise and to the point. I am using a KOMA-Script document class: scrreprt, using the appendix package together with the minitoc package for my chapter format style has been giving me a real headache, though it is solved (in my previously asked question) for the most part, the result was unsatisfactory as I cannot include a \minitoc inside the appendix.

My solution was to go manual and simply change \chaptername name to appendix and the and \thechapter numbering to \Alph{chapter} and subsequently also change the \setcounter so as to get the chapter lettering to start where desired.

This of course meant I had to put it all back at the end of the appendix chapter so that all following chapters would continue unaffected. I was wondering whether there is a way to simply define an environment that sets these parameters (chapter > appendix, chapter numbering > letter, chapter counter) and that allows for the chapter counter to continue between the instances of each repeated environment such that when I put my first environment at the end of the first part it will be called Appendix A and once I put the next one at the end of the second part it will automatically continue form the numbering of the previous environment resulting in Appendix B.

If there is a relatively simple way to do this by defining an environment I would gladly implement that over the manual approach I employed in the below MWE.

\documentclass[
bibliography=totoc,
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}

\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

\begin{document}
\dominitoc
\tableofcontents

\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
% Chapter style change for Appendix
\setcounter{chapter}{0}
\renewcommand{\thechapter}{\Alph{chapter}}
\renewcommand{\chaptername}{Appendix}

\chapter{Test}

\minitoc

Here goes nothing

Done

% Chapter style reset for following chapters
\setcounter{chapter}{7}
\renewcommand{\thechapter}{\arabic{chapter}}
\renewcommand{\chaptername}{Chapter}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\part{Introduction}
%%%%%%%%%%%%%%%%%%%%
\chapter{The 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{Unfortunate Problems}
This chapter does not have a minitoc for some reason
\subsection{Still no minitoc}
\blindtext
\subsubsection{I want to go into the TOC}
\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
\end{document}

• Yes, this is possible, but I do not have time right now to post an answer. I come back later on. – user31729 Jul 8 '14 at 19:37
• @ChristianHupfer Thank you for your reply and thank you for any further help you offer when time permits, I appreciate! – Fiztban Jul 9 '14 at 7:54
• See my answer, perhaps it provides what you request – user31729 Jul 9 '14 at 23:18

In order to achieve the OP's request, some aspects must be considered:

• Restore the chapter number of a true chapter

• Restore the running appendix number

• Restore the counter output formats

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,
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

\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}

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}
\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)

• This is absolutely stunning, the extent of customisability included has left me speechless!! I literally have no negative feedback or minor bugs to report after testing it for a while. Thank you ever so much for your help! – Fiztban Jul 10 '14 at 9:43
• @Fiztban: In your original MWE you have some \addcontentsline statements, I omitted them, as I was unsure about the leveling you desire. If you find some bug(s) please leave a comment or write a mail (see my profile). – user31729 Jul 10 '14 at 9:45
• @ChristianHumpfer Indeed I did notice, but it's not a problem I have already re-written those just so as to have a slight detachment from the TOC elements to identify it as a separate part from the rest. Thank you, I will keep you informed if anything comes up – Fiztban Jul 10 '14 at 9:48
• @Fiztban: Well then, happy TeXing ;-) – user31729 Jul 10 '14 at 9:49