# Show "Appendix A" instead of "A" in the TOC?

As the chapters are numbered in TOC (table of contents) the Appendices are lettered. I want to change that from a single letter "A" to "Appendix A".

A Minimal Working Example:

\documentclass{scrreprt}
\usepackage[utf8]{inputenc}
\title{MWE}
\author{John D.}
\date{February 2020}
\pagenumbering{arabic}

\include{sections/Introduction}
\begin{document}
\tableofcontents

\maketitle
\chapter{This is a section}
\section{This is a subsection}
Some random content
\appendix
\chapter{Numbers}
\section{Numbers 1}
\chapter{Code}
\section{Code 1}

\end{document}


This will Produce: MWE example

• Probably tex.stackexchange.com/a/226497/134144 might be useful. Feb 11, 2020 at 19:55
• Update: I edited MWE: @leandriis I am using a different document class, {\documentclass{article}} but {\documentclass{scrreprt}}. Therefore, appendices are classified as chapters. I tried what it is in the link but did not work! Feb 11, 2020 at 20:09
• Do you just want to change the appearance in the table of contents or also in the document itself? Feb 11, 2020 at 20:15
• @leandriis "Appendix A" should be shown only in the TOC. In the document "A. Appendix name". Feb 11, 2020 at 20:18

You can declare a new TOC style entry appendixchapter using the prefix:

\documentclass{scrreprt}[2019/10/12]% needs version 3.27 or newer
\newcommand\entrywithprefix[2]{#1~#2}
\DeclareTOCStyleEntry[
level:=chapter,
indent:=chapter,
numwidth:=chapter,
dynnumwidth,
entrynumberformat=\entrywithprefix{\appendixname}
]{chapter}{appendixchapter}

\usepackage{xpatch}
\xapptocmd{\appendix}{%
{}{\PatchFailedII}%
}{}{\PatchFailedI}

\title{MWE}
\author{John D.}
\date{February 2020}

\begin{document}
\tableofcontents
\maketitle
\chapter{This is a chapter}
\section{This is a section}
Some random content
\appendix
\chapter{Numbers}
\section{Numbers 1}
\chapter{Code}
\section{Code 1}
\end{document}


Run three times to get

With older KOMA-Script versions use

\DeclareTOCStyleEntry[
level=\chaptertocdepth,
indent=0pt,
numwidth=1.5em,
dynnumwidth,
entrynumberformat=\entrywithprefix{\appendixname}
]{chapter}{appendixchapter}


If you are using numbered bookmarks:

\documentclass{scrreprt}[2019/10/12]% needs version 3.27 or newer
%\providecommand*\Ifstr{\ifstr}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif

\DeclareTOCStyleEntry[
level:=chapter,
indent:=chapter,
numwidth:=chapter,
dynnumwidth,
]{chapter}{appendixchapter}

\usepackage{xpatch}
\xapptocmd{\appendix}{%
{%
\Ifstr{#1}{}
}{}{\PatchFailedII}%
}{}{\PatchFailedI}

\title{MWE}
\author{John D.}
\date{February 2020}

\usepackage[numbered]{bookmark}

\begin{document}
\tableofcontents
\maketitle
\chapter{This is a chapter}
\section{This is a section}
Some random content
\appendix
\chapter{Numbers}
\section{Numbers 1}
\chapter{Code}
\section{Code 1}
\end{document}


• This is exactly what I wanted! Thank you very much. It was a smooth and easy solution! I added the new TOC style entry in my preamble, the first solution suggested, and it worked fine. Feb 12, 2020 at 12:13
• I just noticed that: It is showed right in the TOC but, In the bookmarks of PDF it is shown as a regular chapter. Is there a way to show it some way in the bookmarks of PDF? Feb 12, 2020 at 12:23
• See my updated answer. But there was neither package hyperref nor package bookmark in your MWE.
– esdd
Feb 12, 2020 at 12:44
• I used your updated version. It is shown as I want in TOC and pdf bookmark section. However, when I use the bookmark package I get an error: Missing begin{document} in the preamble. Note: I had hyperref package in my preamble since in the beginning. Feb 12, 2020 at 15:26
• Solved: First Thank you @esdd for the code. Everything is perfect in your code but I have different files for preamble, for main.tex and the chapters. finally, \usepackage[numbered]{bookmark} should be the last thing added to preamble... literally the last, just before \begin{document} Feb 12, 2020 at 15:37