# Appendix entries with colon ONLY in TOC but not in pdfbookmark

I am using scrreprt-class and I am trying to modify the appearance of the appendix titles in the pdfbookmark.

In the image below, you can see what I have at the moment. I am using the appendices-environment and each appendix is a chapter on its own.

Now, I "only" want to add a colon in the ToC for the appendix entries. E.g. Appendix A: I am Appendix a, etc.

Please note that I want to stick to the KOMA-class "scrreprt".

MWE (This is my first one - so I am not sure if it is as minimal as possible)

 \documentclass[12pt, longdoc, bigchapter, colorback, numbersubsubsec, twoside, openright, chapterprefix]{scrreprt}

\usepackage[ngerman]{babel}      % deutsche Trennregeln
\usepackage{lmodern}             % fixes bug with \usepackage[T1]{fontenc}; ändert Schriftart zudem in Latin Modern
\usepackage[T1]{fontenc}         % für europäische Autoren ratsam; % wichtig für Trennung von Wörtern mit Umlauten
\usepackage[utf8]{inputenc}

\usepackage{hyperref}
\usepackage[all]{hypcap}        % needed to help hyperlinks direct correctly;
\usepackage[numbered]{bookmark}
\usepackage{booktabs}

%https://tex.stackexchange.com/questions/202928/remove-last-dot-in-title-numbering
\makeatletter
{\endgraf\nobreak\vskip.5\baselineskip}% <search>
{\hspace*{-0.5em}:\space}% <replace>
{}{}% <success><failure>
\patchcmd{\@chapter}% <cmd>
{}{}% <success><failure>
\protect\patchcmd{\protect\l@chapter}% <cmd>
{1.5em}% <search>
{6.5em}% <replace>
{}{}}% <success><failure>
}
\renewcommand{\autodot}{}% Remove all end-of-counter dots

%%% No Spacing Between Chapter Title and Prefix
\RedeclareSectionCommand[innerskip=0pt]{chapter} % <--- Vary distance here (Thanks @esdd!)

\usepackage[titletoc]{appendix}
\usepackage{lipsum}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

%%% TOC
\phantomsection
\setcounter{tocdepth}{4}
\tableofcontents

%%% Testpage
\chapter{Test}
\lipsum

%%%% APPENDIX
\begin{appendices}
\renewcommand\chaptername{Anhang}
\end{appendices}

\end{document}

• (1) welcome, (2) as always on this site, you are much much more likely to get help if you provide a small but minimal example that others can try or use as a basis. – daleif Sep 29 '17 at 7:26
• thans @daleif! i have provided a MWE. It does not look so minimal, but I would not know how else to get the result in the ToC and pdfbookmarks as shown with less code. – dan Sep 29 '17 at 11:53
• The answer you link to does not take hyperref into account, also, it adds to \appendix but you are using the appendices env. I never use the KOMA stuff, so cannot help here. Note chapter does not actually use \chaptername but rather \@chapapp (at least in normal classes), this points to \chaptername whenever appendix is not active. Thus that \renewcommand does nothing. – daleif Sep 29 '17 at 12:29
• Also remember to copy all the relevant stuff when you copy from an answer. You're missing the package that gives \patchcmd – daleif Sep 29 '17 at 12:41
• @dan You seem to have two accounts... – Andrew Sep 29 '17 at 14:56

Here is a suggestion for the KOMA-Script class scrreprt but without package appendix:

\documentclass[
12pt,
twoside,
openright,
chapterprefix,
numbers=noenddot% <- added: no dots at the end of section numbers etc.
]{scrreprt}

\usepackage[ngerman]{babel}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{hyperref}
\usepackage[all]{hypcap}        % needed to help hyperlinks direct correctly;
\usepackage[numbered]{bookmark}
\usepackage{booktabs}

\RedeclareSectionCommand[innerskip=0pt]{chapter} % <--- Vary distance here (Thanks @esdd!)

\DeclareTOCStyleEntry[
level=\chaptertocdepth,
indent=0pt,
numwidth=2.3em,
dynnumwidth,
entrynumberformat=\appendixtocnumberformat,
]{chapter}{appendixchapter}
\newcommand*\appendixtocnumberformat[1]
{\def\autodot{:}#1}

\usepackage{xpatch}
\xapptocmd{\appendix}
{%
\xpatchcmd{\chapterformat}{\autodot}{:}{}{\PatchFailedII}%
\xpatchcmd{\chaptermarkformat}{\autodot}{:}{}{\PatchFailedIII}%
{%
\ifstr{#1}{}
}{}{\PatchFailedIV}%
}{}{\PatchFailedI}

\usepackage{lipsum}% only for dummy text
\begin{document}
\phantomsection
\setcounter{tocdepth}{4}
\tableofcontents

\chapter{Test}
\lipsum

\appendix
\end{document}


Run three times to get:

Note that I have removed the unused global options longdoc, bigchapter, colorback, numbersubsubsec.

Because of the question in a comment below:

If the colon should also be in the bookmarks you have to added it to the \addtocentrydefault{appendixchapter}{...}{...} line:

\addtocentrydefault{appendixchapter}{\appendixname\ #1:}{#2}


and to change the redefinition of \autodot in \appendixtocnumberformat:

\newcommand*\appendixtocnumberformat[1]
{\def\autodot{}#1}


Complete example with the colon in bookmarks too:

\documentclass[
12pt,
twoside,
openright,
chapterprefix,
numbers=noenddot% <- added: no dots at the end of section numbers etc.
]{scrreprt}

\usepackage[ngerman]{babel}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{hyperref}
\usepackage[all]{hypcap}        % needed to help hyperlinks direct correctly;
\usepackage[numbered]{bookmark}
\usepackage{booktabs}

\RedeclareSectionCommand[innerskip=0pt]{chapter} % <--- Vary distance here (Thanks @esdd!)

\DeclareTOCStyleEntry[
level=\chaptertocdepth,
indent=0pt,
numwidth=2.3em,
dynnumwidth,
entrynumberformat=\appendixtocnumberformat,
]{chapter}{appendixchapter}
\newcommand*\appendixtocnumberformat[1]
{\def\autodot{}#1}% <- changed

\usepackage{xpatch}
\xapptocmd{\appendix}
{%
\xpatchcmd{\chapterformat}{\autodot}{:}{}{\PatchFailedII}%
\xpatchcmd{\chaptermarkformat}{\autodot}{:}{}{\PatchFailedIII}%
{%
\ifstr{#1}{}
}{}{\PatchFailedIV}%
}{}{\PatchFailedI}

\usepackage{lipsum}% only for dummy text
\begin{document}
\phantomsection
\setcounter{tocdepth}{4}
\tableofcontents

\chapter{Test}
\lipsum

\appendix
\end{document}


Result:

• thanks @esdd. Which lines would I have to change to include the colons in the pdfbookmarks as well? I am trying to understand the logic in the code. – dan Oct 3 '17 at 15:34
• See my updated answer. – esdd Oct 3 '17 at 16:18
• I've noticed that the given declaration of the ToC style entry causes the vertical spacing of the appendix ToC entries to be modified from the default. Is there a way to enforce the default vertical spacing? – dan Oct 14 '17 at 16:51
• @dan Thank you for the hint. See my updated answer: I have added beforeskip=1em plus 1pt to the declaration of the new ToC style entry to get the same vertical spacing as for chapters. – esdd Oct 14 '17 at 17:40

Not really an answer, but here i how it could be done using the memoir class

\documentclass[a4paper]{memoir}

\usepackage[ngerman]{babel}      % deutsche Trennregeln
\usepackage{lmodern}             % fixes bug with \usepackage[T1]{fontenc}; ändert Schriftart zudem in Latin Modern
\usepackage[T1]{fontenc}         % für europäische Autoren ratsam; % wichtig für Trennung von Wörtern mit Umlauten
\usepackage[utf8]{inputenc}

\usepackage{hyperref}
\usepackage[numbered]{bookmark}

%\renewcommand\cftchaptername{\chaptername~}
\renewcommand\cftappendixname{\appendixname~}
\makeatletter
\AtBeginDocument{
\bookmarksetup{%
\ifnum\toclevel@chapter=\bookmarkget{level}\relax
\ifanappendix
\renewcommand*{\chapternumberline}[1]{\appendixname~#1:~}%
\fi
\fi
},
}
}
\makeatother

\cftinsertcode{APP}{
\renewcommand\cftchapteraftersnum{:~}
}

\usepackage{lipsum}

\begin{document}

%%% TOC
\phantomsection
\setcounter{tocdepth}{4}
\tableofcontents*

%%% Testpage
\chapter{Test}
\lipsum

%%%% APPENDIX
%\begin{appendices}

\appendix

\cftinserthook{toc}{APP}

%\end{appendices}

\end{document}


A solution independent of the document class would be to simply specify an alternative chapter name for the TOC which includes a colon, and then to correct for the spacing with \hspace. I.e. instead of using

\chapter{This is a test heading}


one can use

\chapter[\hspace{-0.3cm}: This is a test heading]{This is a test heading}


Update: As pointed out by egreg, the above solution will change the headers as well. Since "Appendix " is not always printed in the headers, one could compenstate this by using fancyhdr. For instance

\fancyhead[LO, RE]{\fancyplain{}{\appendixname\hspace{1ex}\thechapter \hspace{0.3cm}\nouppercase\leftmark}}

• Welcome to TeX.SX! The optional entry will also be used for the headers, at least in the standard classes. – egreg Feb 20 '18 at 11:16
• Thank you :-) Good point with the headers. Actually that seems to be quite favorable to me if the alternative name will be used in the headers as well, this is exactly what I would want. As long as the chapter titles are spared since there the "Appendix <X>" is sometimes in a separate line and thus no colon needed. Update: Actually it doesn't work as I expected, since in the header the term "Appendix <X>" is not printed at all... – Jadzia Feb 20 '18 at 13:48