Prepend 'Appendix' before 'A' using scrbook
Add the following lines to your preamble:
\makeatletter
\g@addto@macro\appendix{%
\renewcommand*{\chapterformat}{%
{\chapapp\nobreakspace\thechapter\autodot\enskip}%
}
\renewcommand*{\chaptermarkformat}{%
{\chapapp\nobreakspace\thechapter\autodot\enskip}%
}
\let\oldaddcontentsline\addcontentsline
\newcommand\hackedaddcontentsline[3]{\oldaddcontentsline{#1}{#2}{\chapapp\nobreakspace#3}}
\let\oldchapter\chapter
\renewcommand*\chapter[1]{%
\let\addcontentsline\hackedaddcontentsline%
\oldchapter{#1}%
\let\addcontentsline\oldaddcontentsline%
}
}
\makeatother
With \g@addto@macro
we add to the command \appendix
the following modifications:
- We redefine
\chapterformat
so to add the word "Appendix" before the chapter number. - We redefine
\chaptermarkformat
so to add the word "Appendix" before the chapter number in the header. - The rest of the code redefines the meaning of
\addcontentsline
only for the\chapter
command, so to add the word "Appendix" in the ToC also.
The command \autoref
works as expected.
MWE:
\documentclass[numbers=noenddot]{scrbook}
\usepackage[colorlinks]{hyperref}
\makeatletter
\g@addto@macro\appendix{%
\renewcommand*{\chapterformat}{%
{\chapapp\nobreakspace\thechapter\autodot\enskip}%
}
\renewcommand*{\chaptermarkformat}{%
{\chapapp\nobreakspace\thechapter\autodot\enskip}%
}
\let\oldaddcontentsline\addcontentsline
\newcommand\hackedaddcontentsline[3]{\oldaddcontentsline{#1}{#2}{\chapapp\nobreakspace#3}}
\let\oldchapter\chapter
\renewcommand*\chapter[1]{%
\let\addcontentsline\hackedaddcontentsline%
\oldchapter{#1}%
\let\addcontentsline\oldaddcontentsline%
}
}
\makeatother
\begin{document}
\tableofcontents
\chapter{1st chapter}
\section{1st section}
\chapter{2nd chapter}
\section{2nd section}
\appendix
\chapter{1st appendix chapter}\label{app:first}
\section{1st appendix section}
\chapter{2nd appendix chapter}
\section{2nd appendix section}
\autoref{app:first}
\end{document}
Output (ToC)
Output (An appendix)
Here is a suggestion that needs KOMA-Script version 3.20 or newer:
\documentclass[
oneside,
numbers=noenddot,
appendixprefix
]{scrbook}[2016/05/10]% needs version 3.20 or newer
\usepackage{blindtext}% dummy text
\usepackage{xpatch}
\xapptocmd{\appendix}{%
\addtocontents{toc}{%
\RedeclareSectionCommand[
tocdynnumwidth,
tocentrynumberformat=\tocappendixnumber
]{chapter}%
}%
}{}{\PatchFailed}
\newcommand\tocappendixnumber[1]{\chapapp~#1}
\usepackage{hyperref}
\begin{document}
\tableofcontents
\blinddocument
\appendix
\chapter{First chapter in appendix}\label{app:first}
\section{Section in appendix}
See \autoref{app:first}
\Blindtext[10]
\blinddocument
\end{document}
Run three times to get:
For the formatting of title in the form Appendix A (title)
and entries in the TOC
, there is a 'quick-and-dirty' solution, by redefinition of the section
command, however, not the \autoref
issue.
\documentclass{scrbook}
\usepackage[manualmark]{scrpage2}
\usepackage{blindtext} % Not really needed
\usepackage{hyperref}
\newcommand*{\CurrentSectionTitle}[1]{#1}%
\begin{document}
\tableofcontents
\chapter{Some Content}
\section{Hello}
In \autoref{Section::NumberTwo} it is shown that \[ E = m c^2 \]
\section{Hello Again}
\label{Section::NumberTwo}%
In \autoref{Appendix::B} it is shown again that \[ E = m c^2 \]
holds.
\cleardoublepage
%%%% Now appendix stuff
% Set counter format to letters
\renewcommand{\thesection}{\Alph{section}}
\let\LaTeXStandardSection\section
% Quick and dirty version of a `section wrapper`
\renewcommand*{\section}[1]{% Does not work if optional argument is desired!
\renewcommand*{\CurrentSectionTitle}{#1}%
\refstepcounter{section}% Needed, since starred version of section command (see below)
\addcontentsline{toc}{chapter}{\protect{\appendixname~\thesection~\CurrentSectionTitle}} % Change if not appropiate format
%Prevent entry with number in TOC, since starred version of standard section command
\LaTeXStandardSection*{\appendixname~\thesection~\CurrentSectionTitle}%
}%
\pagestyle{scrheadings}
\appendix
\section{Number One}
\blindtext[5] % Some dummy text
\section{Number Two}
\label{Appendix::B}
\blindtext
\section{Number Three}
\blindtext
\end{document}
As said above, this is a quick and dirty solution, perhaps there are better approaches than redefining the section command (which is in my case not completely done, since it does not allow for TOC
short titles)
Concerning the \autoref
, there is a \sectionautorefname
command which can be redefined to
\renewcommand*{\sectionautorefname}{\appendixname}
however, this will be used at any occurence of a section autoreference afterwards. I have not found a solution so far to bypass this.