使用 scrreprt 缩进章节、部分……目录中附录的条目以及书签

使用 scrreprt 缩进章节、部分……目录中附录的条目以及书签

我想要此示例代码的目录和 pdf 书签:

\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}

像这样:

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

我有一个非常类似的问题,但此解决方案不起作用。它只是chapter@@section section@@subsection在目录中打印。

到目前为止,我的解决方案是将其放在\addcontentsline{toc}{part}{Appendix}附录前面,但这只能解决书签问题。

答案1

我不建议对 TOC 结构进行这样的更改,但这是可能的:

\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}

在此处输入图片描述

或者,如果选项listof=chaptergaplinelistof=chapterentry也应影响附录“章节”的 LOF 和 LOT 中的条目:

\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}

相关内容