[Tex/LaTex] Prepend ‘Appendix’ before ‘A’ using scrbook

appendicesheader-footerscrbooksectioningtable of contents

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.

Appendix Title

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

TOC Output

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}

\setlength{\headheight}{15pt}

\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}
\usepackage[colorlinks]{hyperref}

\setlength{\headheight}{15pt}

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

\begin{document}

\frontmatter
\tableofcontents

\mainmatter
\blinddocument

\appendix

\chapter{More Information} \label{app:first}
\section{Another Section}
\autoref{app:first} 
\Blindtext

\end{document}

Best Answer

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:

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

enter image description here

Output (An appendix)

enter image description here