在目录中显示“附录 A”而不是“A”?

在目录中显示“附录 A”而不是“A”?

由于章节在 TOC(目录)中是编号的,因此附录也以字母表示。我想将其从单个字母“A”更改为“附录 A”。

最小工作示例:

\documentclass{scrreprt}
\usepackage[utf8]{inputenc}
\title{MWE}
\author{John D.}
\date{February 2020}
\pagenumbering{arabic}

\include{sections/Introduction}
\begin{document}
\tableofcontents

\maketitle
\chapter{This is a section}
\section{This is a subsection}
Some random content
\appendix
\chapter{Numbers}
\section{Numbers 1}
\chapter{Code}
\section{Code 1}

\end{document}

这将产生: MWE 示例

答案1

appendixchapter您可以使用前缀声明新的 TOC 样式条目:

\documentclass{scrreprt}[2019/10/12]% needs version 3.27 or newer
\newcommand\entrywithprefix[2]{#1~#2}
\DeclareTOCStyleEntry[
  level:=chapter,
  indent:=chapter,
  numwidth:=chapter,
  dynnumwidth,
  entrynumberformat=\entrywithprefix{\appendixname}
]{chapter}{appendixchapter}

\usepackage{xpatch}
\xapptocmd{\appendix}{%
  \xpatchcmd{\addchaptertocentry}
    {\addtocentrydefault{chapter}{#1}{#2}}
    {\addtocentrydefault{appendixchapter}{#1}{#2}}
    {}{\PatchFailedII}%
  }{}{\PatchFailedI}

\title{MWE}
\author{John D.}
\date{February 2020}

\begin{document}
\tableofcontents
\maketitle
\chapter{This is a chapter}
\section{This is a section}
Some random content
\appendix
\chapter{Numbers}
\section{Numbers 1}
\chapter{Code}
\section{Code 1}
\end{document}

运行三次即可获得

在此处输入图片描述


对于旧版 KOMA-Script,使用

\DeclareTOCStyleEntry[
  level=\chaptertocdepth,
  indent=0pt,
  numwidth=1.5em,
  dynnumwidth,
  entrynumberformat=\entrywithprefix{\appendixname}
]{chapter}{appendixchapter}

如果你正在使用编号书签

\documentclass{scrreprt}[2019/10/12]% needs version 3.27 or newer
%\providecommand*\Ifstr{\ifstr}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif

\DeclareTOCStyleEntry[
  level:=chapter,
  indent:=chapter,
  numwidth:=chapter,
  dynnumwidth,
]{chapter}{appendixchapter}

\usepackage{xpatch}
\xapptocmd{\appendix}{%
\xpatchcmd{\addchaptertocentry}
  {\addtocentrydefault{chapter}{#1}{#2}}
  {%
    \Ifstr{#1}{}
      {\addtocentrydefault{appendixchapter}{}{#2}}
      {\addtocentrydefault{appendixchapter}{\appendixname~#1}{#2}}%
  }{}{\PatchFailedII}%
}{}{\PatchFailedI}

\title{MWE}
\author{John D.}
\date{February 2020}

\usepackage[numbered]{bookmark}

\begin{document}
\tableofcontents
\maketitle
\chapter{This is a chapter}
\section{This is a section}
Some random content
\appendix
\chapter{Numbers}
\section{Numbers 1}
\chapter{Code}
\section{Code 1}
\end{document}

在此处输入图片描述

相关内容