# Prepend 'Appendix' before 'A' using scrbook

I am writing my thesis and need to put 'Appendix' before the numbering (A, B, C, ...) in the table of contents (TOC), the chapter title and in the header. I'd also like for \autoref{} to output 'Appendix A'.

I am using the scrbook class and have tried several different ways to achieve this but nothing gives me the desired output.

I want the title to appear as below so that it reads 'Appendix A (Title)'. This is also how I want it to appear in the TOC and in my header.

I've tried using the KOMA option appendixprefix=true but this splits Appendix A and More Information onto separate lines and doesn't put 'Appendix' before A in the TOC.

I've tried redefining \thechapter with \renewcommand{\thechapter}{Appendix \Alph{chapter} which gives me the desired output in the title and header of my document but the table of contents output is below and \autoref{}'s output is 'Appendix Appendix A'.

I've tried the appendix package too but this won't add Appendix to the title in the main body, only to the TOC.

I've also tried some other hacks which work in both the TOC and the title but then show the previous chapter in the header.

I set my headers using the following

\usepackage{fancyhdr}

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{ \markboth{\thechapter~#1}{} } % Adds chapter number name to right header
\renewcommand{\sectionmark}[1]{ \markright{\thesection~#1}{} } % Adds section name to left header


I'd really appreciate some help with this as I can't find a solution which works for my 3 main cases of title, TOC and header using the scrbook class.

MWE:

\documentclass[12pt,a4paper,oneside,pointlessnumbers]{scrbook}

\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{fancyhdr}

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{ \markboth{\thechapter~#1}{} }
\renewcommand{\sectionmark}[1]{ \markright{\thesection~#1}{} }

\begin{document}

\frontmatter
\tableofcontents

\mainmatter
\blinddocument

\appendix

\section{Another Section}
\autoref{app:first}
\Blindtext

\end{document}

• Welcome to TeX.SX! Help us to help you: Please add a full minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. Mar 6, 2014 at 2:25
• Please read KOMA-Script documentation for class option chapterprefix and \KOMAoption/\KOMAoptions. Also consider using the KOMA-Script package scrlayer-scrpage instead of fancyhdr. The switch should not be that hard. Mar 6, 2014 at 2:32
• Doesn't my answer work for you? Mar 6, 2014 at 11:06
• @karlkoeller Sorry for the delay in commenting on your answer. It didn't work perfectly for me and I just wanted to see if I could add something to it to make it work for me. Mar 6, 2014 at 11:20

Add the following lines to your preamble:

\makeatletter
\renewcommand*{\chapterformat}{%
{\chapapp\nobreakspace\thechapter\autodot\enskip}%
}
\renewcommand*{\chaptermarkformat}{%
{\chapapp\nobreakspace\thechapter\autodot\enskip}%
}
\let\oldchapter\chapter
\renewcommand*\chapter[1]{%
\oldchapter{#1}%
}
}
\makeatother


With \g@addto@macro we add to the command \appendix the following modifications:

1. We redefine \chapterformat so to add the word "Appendix" before the chapter number.
2. We redefine \chaptermarkformat so to add the word "Appendix" before the chapter number in the header.
3. 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}

\makeatletter
\renewcommand*{\chapterformat}{%
{\chapapp\nobreakspace\thechapter\autodot\enskip}%
}
\renewcommand*{\chaptermarkformat}{%
{\chapapp\nobreakspace\thechapter\autodot\enskip}%
}
\let\oldchapter\chapter
\renewcommand*\chapter[1]{%
\oldchapter{#1}%
}
}
\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)

• Thanks for the great answer and explanation. That works perfectly for the TOC, the chapter title and \autoref but it doesn't show 'Appendix' before 'B 2nd appendix chapter' in my page title which I set using '\thechapter~#1'. Do I need to change how I'm setting my page headers? Mar 6, 2014 at 11:19
• @karlkoeller i seem to have the problem that this solution affects the title of my bibliography (using biblatex/biber), is there an easy way to solve this? (if i simply place my bibliography before appendices it's fine, but that's not the place my bibliography has to go) Mar 10, 2015 at 13:36
• @Charles-AlexandreMattelaer It affects everything following the \appendix command, including a bibliography. Try adding in the preamble \usepackage{etoolbox} \pretocmd\thebibliography{% \let\chapter\oldchapter% }{}{}. A space in this code means a linebreak. Mar 10, 2015 at 20:04
• @Charles-AlexandreMattelaer Are you using biblatex? If yes, replace \thebibliography with \printbibliography Mar 12, 2015 at 9:56
• @karlkoeller Great answer; but like Charles-Alexandre, I had to make use of your further comments to really make this work. Perhaps it would be a good idea to incorporate these into the main body of the text?
– Danu
Sep 19, 2017 at 17:40

Update using LaTeX version 2021/06/01 and KOMA-Script version 3.34:

\documentclass[
oneside,
numbers=noenddot
]{scrbook}
\usepackage{blindtext}% dummy text
\usepackage{biblatex}

}

\NewDocumentCommand{\appendixtocentry}{}{%
\DeclareTOCStyleEntry[
entrynumberformat=\tocappendixnumber,
dynnumwidth
]{chapter}{chapter}%
}
\NewDocumentCommand{\tocappendixnumber}{m}{%
\appendixname~#1%
}

\begin{document}
\tableofcontents
\blinddocument
\appendix
\chapter{First chapter in appendix}\label{app:first}
\section{Section in appendix}
See \autoref{app:first}

\Blindtext[10]
\blinddocument

\nocite{*}
\end{document}


Run three times to get

Update using (final) TL2018 or newer:

\documentclass[
oneside,
numbers=noenddot,
appendixprefix
]{scrbook}
\usepackage{blindtext}% dummy text

\usepackage{xpatch}
\xapptocmd{\appendix}{%
\renewcommand*{\chapterformat}{\chapapp\nobreakspace\thechapter\autodot\enskip}%
\renewcommand*{\chaptermarkformat}{\chapapp\nobreakspace\thechapter\autodot\enskip}%
\RedeclareSectionCommand[
tocdynnumwidth,
tocentrynumberformat=\tocappendixnumber
]{chapter}%
}%
}{}{\PatchFailed}
\newcommand\tocappendixnumber[1]{\chapapp~#1}

\usepackage{biblatex}

\begin{document}
\tableofcontents
\blinddocument
\appendix
\chapter{First chapter in appendix}\label{app:first}
\section{Section in appendix}
See \autoref{app:first}

\Blindtext[10]
\blinddocument

\nocite{*}
\end{document}


Run three times to get

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

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