1

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

Thanks in advance.

enter image description here

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}           
\hypersetup{linktocpage=true,  linktoc=all,bookmarks=true, bookmarksopen=true, colorlinks, linkcolor = black}
\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
\g@addto@macro{\appendix}{%
    \patchcmd{\@@makechapterhead}% <cmd>
    {\endgraf\nobreak\vskip.5\baselineskip}% <search>
    {\hspace*{-0.5em}:\space}% <replace>
    {}{}% <success><failure>
    \patchcmd{\@chapter}% <cmd>
    {\addchaptertocentry{\thechapter}}% <search>
    {\addchaptertocentry{Appendix~\thechapter:}}% <replace>
    {}{}% <success><failure>
    \addtocontents{toc}{%
        \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                             
\pdfbookmark{Inhaltsverzeichnis}{toc}   %Inhaltsverzeichnis in die Hyperlink-Navigation mit aufnehmen 
%\addcontentsline{toc}{chapter}{Inhaltsverzeichnis}
\setcounter{tocdepth}{4}
\tableofcontents

%%% Testpage
\chapter{Test}
\lipsum

%%%% APPENDIX
\begin{appendices}
\renewcommand\chaptername{Anhang}
\chapter{This is a test heading}
\end{appendices}


\end{document}
5
  • 1
    (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
    Commented Sep 29, 2017 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
    Commented Sep 29, 2017 at 11:53
  • 1
    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
    Commented Sep 29, 2017 at 12:29
  • 1
    Also remember to copy all the relevant stuff when you copy from an answer. You're missing the package that gives \patchcmd
    – daleif
    Commented Sep 29, 2017 at 12:41
  • @dan You seem to have two accounts...
    – user30471
    Commented Sep 29, 2017 at 14:56

3 Answers 3

4

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}
\hypersetup{linktoc=all,bookmarksopen=true, colorlinks, linkcolor = black}
\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}%
    \xpatchcmd{\addchaptertocentry}
      {\addtocentrydefault{chapter}{#1}{#2}}
      {%
        \ifstr{#1}{}
          {\addtocentrydefault{chapter}{}{#2}}
          {\addtocentrydefault{appendixchapter}{\appendixname\ #1}{#2}}%
      }{}{\PatchFailedIV}%
  }{}{\PatchFailedI}

\usepackage{lipsum}% only for dummy text
\begin{document}
\phantomsection
\pdfbookmark{Inhaltsverzeichnis}{toc}   %Inhaltsverzeichnis in die Hyperlink-Navigation
\setcounter{tocdepth}{4}
\tableofcontents

\chapter{Test}
\lipsum

\appendix
\chapter{This is a test heading}
\end{document}

Run three times to get:

enter image description here

enter image description here

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}
\hypersetup{linktoc=all,bookmarksopen=true, colorlinks, linkcolor = black}
\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}%
    \xpatchcmd{\addchaptertocentry}
      {\addtocentrydefault{chapter}{#1}{#2}}
      {%
        \ifstr{#1}{}
          {\addtocentrydefault{chapter}{}{#2}}
          {\addtocentrydefault{appendixchapter}{\appendixname\ #1:}{#2}}% <- changed
      }{}{\PatchFailedIV}%
  }{}{\PatchFailedI}

\usepackage{lipsum}% only for dummy text
\begin{document}
\phantomsection
\pdfbookmark{Inhaltsverzeichnis}{toc}   %Inhaltsverzeichnis in die Hyperlink-Navigation
\setcounter{tocdepth}{4}
\tableofcontents

\chapter{Test}
\lipsum

\appendix
\chapter{This is a test heading}
\end{document}

Result: enter image description here

4
  • 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
    Commented Oct 3, 2017 at 15:34
  • 1
    See my updated answer.
    – esdd
    Commented Oct 3, 2017 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
    Commented Oct 14, 2017 at 16:51
  • 1
    @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
    Commented Oct 14, 2017 at 17:40
2

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}           
\hypersetup{linktocpage=true,  linktoc=all,bookmarks=true, bookmarksopen=true, colorlinks, linkcolor = black}
\usepackage[numbered]{bookmark}

%\renewcommand\cftchaptername{\chaptername~}
\renewcommand\cftappendixname{\appendixname~}
\makeatletter
\AtBeginDocument{
\bookmarksetup{%
 addtohook={%
   \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                             
\pdfbookmark{Inhaltsverzeichnis}{toc}   %Inhaltsverzeichnis in die Hyperlink-Navigation mit aufnehmen 
%\addcontentsline{toc}{chapter}{Inhaltsverzeichnis}
\setcounter{tocdepth}{4}
\tableofcontents*

%%% Testpage
\chapter{Test}
\lipsum

%%%% APPENDIX
%\begin{appendices}

\appendix

\cftinserthook{toc}{APP}


\chapter{This is a test heading}
%\end{appendices}


\end{document}
1

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}

enter image description here

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}}
2
  • Welcome to TeX.SX! The optional entry will also be used for the headers, at least in the standard classes.
    – egreg
    Commented Feb 20, 2018 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
    Commented Feb 20, 2018 at 13:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .