1

I want my table of contents and pdf-bookmarks of this example-code:

\documentclass{scrreprt}
\begin{document}
  \chapter{First Chapter}
  \section{First Section of First Chapter}
  \section{Secont Section of First Chapter}
  \chapter{Second Chapter}
  \section{First Section of Second Chapter}
  \section{Secont Section of Second Chapter}
  \addcontentsline{toc}{chapter}{Appendix}
  \appendix
  \chapter{First Appendix}
  \section{First Section of First Appendix}
  \section{Secont Section of First Appendix}
  \chapter{Second Appendix}
  \section{First Section of Second Appendix}
  \section{Secont Section of Second Appendix}
\end{document}

like this:

1. First Chapter
   1.1 First Section of First Chapter
   1.2 Second Section of First Chapter
2. First Chapter
   2.1 First Section of Second Chapter
   2.2 Second Section of Second Chapter
Appendix
   A. First Appendix
      A.1 First Section of First Appendix
      A.2 Second Section of First Appendix
   B. First Appendix
      B.1 First Section of Second Appendix
      B.2 Second Section of Second Appendix

I have a problem quite similar to this, but this solution does not work. It just prints chapter@@section section@@subsection in the TOC.

My solution so far is to put \addcontentsline{toc}{part}{Appendix} in front of the appendencies, but this only fix the bookmark-issue.

2

I do not recommend such a change of the TOC structure, but it is possible:

\documentclass{scrreprt}

\usepackage{xpatch}
\xapptocmd{\appendix}{%
    \cleardoublepage
    \addchaptertocentry{}{\appendixname}%
    \ChapAsSecInTOC
    \SecAsSubsecInTOC
  }{}{\AppendixPatchFailed}
\newcommand*\ChapAsSecInTOC{%
  \renewcommand*\addchaptertocentry[2]
    {\addtocentrydefault{section}{##1}{##2}}%
}
\newcommand*\SecAsSubsecInTOC{%
  \renewcommand*\addsectiontocentry[2]
    {\addtocentrydefault{subsection}{##1}{##2}}%
}

\usepackage{bookmark}
\begin{document}
\tableofcontents
\chapter{First Chapter}
\section{First Section of First Chapter}
\section{Secont Section of First Chapter}
\chapter{Second Chapter}
\section{First Section of Second Chapter}
\section{Secont Section of Second Chapter}
\appendix
\chapter{First Appendix}
\section{First Section of First Appendix}
\section{Secont Section of First Appendix}
\chapter{Second Appendix}
\section{First Section of Second Appendix}
\section{Secont Section of Second Appendix}
\end{document}

enter image description here

Or if options listof=chaptergapline, listof=chapterentry etc. should affect entries in LOF and LOT for appendix "chapters", too:

\documentclass{scrreprt}

\usepackage{xpatch}
\xapptocmd{\appendix}{%
    \cleardoublepage
    \addchaptertocentry{}{\appendixname}%
    \ChapAsSecInTOC
    \SecAsSubsecInTOC
  }{}{\AppendixPatchFailed}
\newcommand*\ChapAsSecInTOC{%
  \xpatchcmd{\addchaptertocentry}
    {\addtocentrydefault{chapter}}
    {\addtocentrydefault{section}}
    {}{\PatchFailedI}%
}
\newcommand*\SecAsSubsecInTOC{%
  \renewcommand*\addsectiontocentry[2]
    {\addtocentrydefault{subsection}{##1}{##2}}%
}

\usepackage{bookmark}
\begin{document}
\tableofcontents
\chapter{First Chapter}
\section{First Section of First Chapter}
\section{Secont Section of First Chapter}
\chapter{Second Chapter}
\section{First Section of Second Chapter}
\section{Secont Section of Second Chapter}
\appendix
\chapter{First Appendix}
\section{First Section of First Appendix}
\section{Secont Section of First Appendix}
\chapter{Second Appendix}
\section{First Section of Second Appendix}
\section{Secont Section of Second Appendix}
\end{document}
  • yep, that does the thing. :) – sivizius May 11 '18 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.