4

Four questions concerning appendix entries in the ToC:

  1. As you can see in the attached picture, I want the page numbers for each appendix entry to be not bold, but normal font (like those of sections). Only the Appendix itself (introduced with a page with the word "Appendix" on it) should have a bold one because it is treated like a chapter.

  2. I would like to have these dots for each sub-appendix entry (Appendix 1, Appendix 2, ...) (again like in the section entries).

  3. I'm not happy with the indentation you can see in the picture if there is more than one line for a sub-appendix entry. I'd like to arrange it like demonstrated in the attached picture.

  4. Is there a way to reduce the spacing between the sub-appendix entries? (analogue to the behaviour with sections, subsections, ...)

enter image description here

\documentclass[%
    fontsize        =   12pt,
    BCOR            =   10mm,
    DIV             =   calc,
    chapterprefix   =   true,
    headings        =   big,
    toc             =   bibliography,
    toc             =   listof,
    numbers         =   noenddot]
    {scrreprt}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}                            
\usepackage[utf8]{inputenc}                     
\usepackage{etoolbox}
\providecommand*{\appendixmore}{}
\newcommand*{\SavedOriginaladdchaptertocentry}{}
\appto\appendixmore{%
\let\SavedOriginaladdchaptertocentry\addchaptertocentry
\renewcommand*{\addchaptertocentry}[2]{%
\ifstr{#1}{}{%
\SavedOriginaladdchaptertocentry{}{#2}%
}{%
\SavedOriginaladdchaptertocentry{}{\normalfont\small\appendixname~#1:\enskip#2}%
}%
}%
}
\usepackage[%
    bookmarks           =   true,
    bookmarksopen       =   false,
    bookmarksnumbered   =   true,
    pdfcenterwindow     =   true,
    pdfdisplaydoctitle  =   true,
    pdfencoding         =   auto,
    pdffitwindow            =   false,
    pdfstartview            =   FitV,
    draft               =   false]
    {hyperref}

\begin{document}                            

\pagenumbering{Roman}
\tableofcontents


\chapter{I am Chapter One}

\pagenumbering{arabic}                              

Test.

\section{Test}

\section{Test Test}

\chapter{I am Chapter Two}

\pagestyle{empty}
\clearpage

\phantomsection                                     
\vspace*{\fill}
\begin{center}
{\Huge\bfseries{Appendix}}
\end{center}
\vspace*{\fill}
\thispagestyle{empty}
\addcontentsline{toc}{chapter}{Appendix}

\appendix

\setkomafont{chapter}{\normalsize}

\renewcommand*{\thechapter}{\arabic{chapter}}

\chapter{\texorpdfstring{I am the first appendix with a long heading that takes more than just one line}{I am the first appendix with a long heading that takes more than just one line}}

\chapter{\texorpdfstring{I am the second appendix with a long heading that takes more than just one line}{I am the second appendix with a long heading that takes more than just one line}}

\end{document}
2
  • 1
    Well, to be honest, there is one chapter appendix, when you just got one appendix. Every appendix (figures, diagrams, schemes, otherStuff) should be a chapter of its own. That's why there is an \appendix switch, that changes the numbering scheme.
    – Johannes_B
    Commented Oct 17, 2015 at 16:02
  • I see your point, but, unfortunately, my university guide lines say that it has to be like that. Using section instead of chapter for an appendix does not help because then it generates entries like "Appendix 0.1" or "Appendix 0.2". I'm not a professional LaTeX User so I'd really appreciate some help.
    – SeMe
    Commented Oct 17, 2015 at 16:10

2 Answers 2

4

An alternative solution.

semeKomaTocAppendicToc

\documentclass[%
    fontsize      = 12pt,
    BCOR          = 10mm,
    DIV           = calc,
    chapterprefix = true,
    headings      = big,
    toc           = bibliography,
    toc           = listof,
    toc           = indentunnumbered,%JB Optionally indent unnumbered chapters
numbers         = noenddot
]
{scrreprt}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{hyperref}
\begin{document}

\pagenumbering{Roman}
\tableofcontents


\chapter{I am Chapter One}
\pagenumbering{arabic}

Test.

\section{Test}

\section{Test Test}

\chapter{I am Chapter Two}

\cleardoublepage
\appendix
\vspace*{\fill}
\begin{center}
    {\Huge\bfseries\sffamily Appendix}
    \addchaptertocentry{}{Appendix}
\end{center}
\vspace*{\fill}


\renewcommand{\thechapter}{\appendixname~\Alph{chapter}}
\KOMAoptions{chapterprefix=false}
\renewcommand{\chapterlinesformat}[3]{#2\chapterheadmidvskip#3}
\addtocontents{toc}{
\protect\setkomafont{chapterentry}{\protect\normalfont\protect\normalcolor}
\protect\KOMAoptions{chapterentrydots}
\RedeclareSectionCommand[
    tocnumwidth=6em
]{chapter}
}


\chapter{\texorpdfstring{I am the first appendix with a long heading that takes more than just one line}{I am the first appendix with a long heading that takes more than just one line}}

\chapter{\texorpdfstring{I am the second appendix with a long heading that takes more than just one line}{I am the second appendix with a long heading that takes more than just one line}}

\end{document}
3
  • that is quite some hacking here.
    – Johannes_B
    Commented Oct 17, 2015 at 17:22
  • @esdd I hope you can provide a simpler solution. :-) Maybe a leveldown feature can be implemented, since this requirement seems to be common right now.
    – Johannes_B
    Commented Oct 17, 2015 at 19:06
  • This solution works fine for me, now. Important for future users: Update your KOMA-Script Package, at first I got a couple of error messages because I used the KOMA version coming with MacTex 2014. After an upgrade to MacTex 2015, everything works fine. Thanks a lot to you and esdd.
    – SeMe
    Commented Oct 18, 2015 at 15:03
5

As @Johannes have said in a comment: every appendix should be a chapter of its own. It is not useful to change the behavior of chapter entries inside the ToC.

You can define an \appendixsection command similar to \section using:

\DeclareSectionCommand[%
  style=section,%
  indent=0pt,%
  level=1,%
  beforeskip=-3.5ex plus -1ex minus -.2ex,%
  afterskip=2.3ex plus.2ex,%
  tocindent=1.5em,% same indentation as the sections
  tocnumwidth=6em,%
  font=\usekomafont{section}% same font as the section titles
]{appendixsection}
\makeatletter
  \def\toclevel@appendixsection{1}% set the toclevel for hyperref
\makeatother

Then you can format the entry in the ToC using

\renewcommand\addappendixsectiontocentry[2]{
  \addtocentrydefault{appendixsection}{\appendixname~#1:}{#2}%
}

enter image description here

and the heading in the text

\renewcommand\appendixsectionformat{\appendixname~\theappendixsection}
\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \ifstr{#1}{appendixsection}{%
    #3\par#4%
  }{%
    \@hangfrom{\hskip #2#3}{#4}%
  }%
}
\makeatother

enter image description here

Code:

\documentclass[%
    fontsize        =   12pt,
    BCOR            =   10mm,
    DIV             =   calc,
    chapterprefix   =   true,
    headings        =   big,
    toc             =   bibliography,
    toc             =   listof,
    numbers         =   noenddot]
    {scrreprt}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
%
\DeclareSectionCommand[%
  style=section,%
  indent=0pt,%
  level=1,%
  beforeskip=-3.5ex plus -1ex minus -.2ex,%
  afterskip=2.3ex plus.2ex,%
  tocindent=1.5em,%
  tocnumwidth=6em,%
  font=\usekomafont{section}% or \normalsize if desired
]{appendixsection}
\makeatletter
  \def\toclevel@appendixsection{1}% set the toclevel for hyperref
\makeatother

% format the toc entry
\renewcommand\addappendixsectiontocentry[2]{
  \addtocentrydefault{appendixsection}{\appendixname~#1:}{#2}%
}
% format the heading
\renewcommand\appendixsectionformat{\appendixname~\theappendixsection}
\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \ifstr{#1}{appendixsection}{%
    #3\par#4%
  }{%
    \@hangfrom{\hskip #2#3}{#4}%
  }%
}
\makeatother
%
\usepackage{xpatch}
\xpretocmd{\appendixsection}{\cleardoublepage}{}{}% if every \myappendix should start a new page
\xapptocmd{\appendix}{
  \clearpage
  \thispagestyle{empty}
  \phantomsection
  \vspace*{\fill}
  \begin{center}
  {\Huge\bfseries{\appendixname}}
  \end{center}
  \vspace*{\fill}
  \addcontentsline{toc}{chapter}{\appendixname}
}{}{}

\usepackage[%
    bookmarks           =   true,
    bookmarksopen       =   false,
    bookmarksnumbered   =   true,
    pdfcenterwindow     =   true,
    pdfdisplaydoctitle  =   true,
    pdfencoding         =   auto,
    pdffitwindow            =   false,
    pdfstartview            =   FitV,
    draft               =   false]
    {hyperref}

\begin{document}                            
\pagenumbering{Roman}
\tableofcontents
\chapter{I am Chapter One}
\pagenumbering{arabic}
Test.
\section{Test}
\section{Test Test}
\chapter{I am Chapter Two}

\appendix
\appendixsection{I am the first appendix with a long heading that takes more than just one line}
\appendixsection{I am the second appendix with a long heading that takes more than just one line}
\end{document}
8
  • Nice, would you say my solution (hack) is so bad that i should better delete it? If so, i'll gladly do. I don't like hacks. Alone, your solution feels like a hack as well. Have you seen the comment under my answer?
    – Johannes_B
    Commented Oct 17, 2015 at 20:01
  • appendixtoc is also quite common it seems. Is a solid implementation planned? Alls this hacky stuff will put new users off.
    – Johannes_B
    Commented Oct 17, 2015 at 20:16
  • @Johannes_B AFAIK \DeclareSectionCommand etc. will get an option tocstyle=section in the next version. Das eigentliche Problem ist hier der Wunsch nach einer inkonsistenten Formatierung im Dokument und im Inhaltsverzeichnis, egal welche Klasse genutzt wird.
    – esdd
    Commented Oct 18, 2015 at 5:26
  • Dann hätte ich ja gleich auf Deutsch fragen können. Ja, die Inkonsistenz finde ich auch nicht schön, aber bevor ich dafür Abzüge in der Note bekomme (ist bei mir schon vorgekommen), halte ich mich lieber an die Vorgaben. (The inconsistence is pretty bad, but some universities, unfortunately, have poor guidelines as to how to format a paper.)
    – SeMe
    Commented Oct 18, 2015 at 9:30
  • @esdd: your solution works fine, but gives rise to another problem. Now, the headings in the appendix do not behave according to my guidelines. I need the format [Appendix] + [Number of Appendix] LINEBREAK [Title of the Appendix]. Is there a way to define the ToC style and the (in this case) section style independently from each other?
    – SeMe
    Commented Oct 18, 2015 at 9:38

You must log in to answer this question.

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