KOMA-script:在目录中写入“附录”

KOMA-script:在目录中写入“附录”

我有

\newcommand*{\appendixmore}{%
\renewcommand*{\sectionformat}{%
\appendixname~\thesection\autodot\enskip}%
\renewcommand*{\sectionmarkformat}{%
\appendixname~\thesection\autodot\enskip}}

来自 KOMA 脚本第 517 页,导致“附录”一词出现在附录中的章节之前。

我如何在目录中实现这一点?

1. A Section
Appendix A. A Section in the Appendix
            A.1. A Subsection in the Appendix 
Appendix B. Another Section in the Appendix

梅威瑟:

在此处输入图片描述

\documentclass[english]{scrartcl} 
\usepackage{babel}

\newcommand*{\appendixmore}{%
\renewcommand*{\sectionformat}{%
\appendixname~\thesection\autodot\enskip}%
\renewcommand*{\sectionmarkformat}{%
\appendixname~\thesection\autodot\enskip}}

\begin{document}
\tableofcontents   
 \section{A Section} ...
 \appendix       
\section{A Section in the Appendix} ...
\subsection{A Subsection in the Appendix} ...
\section{Another Section in the Appendix} ...
\end{document}

答案1

更新:

自 KOMA-Script 版本 3.31 起,选项dynindent可用于以下可选参数\DeclareTOCStyleEntries

\documentclass[english]{scrartcl}[2020/07/22]% needs version 3.31 or newer
\usepackage{blindtext}% only for dummy text
\usepackage{babel}
\usepackage{xparse}
\usepackage{calc}

\newcommand\useprefix[2]{#1#2}

\NewDocumentCommand\appendixprefixintoc{}
{%
  \DeclareTOCStyleEntry
    [%
      entrynumberformat=\useprefix{\appendixname~},% add the prefix before the entrynumber
      dynnumwidth
    ]{default}{section}
  \DeclareTOCStyleEntries[%
    dynindent
  ]{default}{subsection,subsubsection,paragraph,subparagraph}
}

\newcommand*{\appendixmore}{%
  \renewcommand*{\sectionformat}{%
    \appendixname~\thesection\autodot\enskip}%
  \renewcommand*{\sectionmarkformat}{%
    \appendixname~\thesection\autodot\enskip}%
  \addtocontents{toc}{\appendixprefixintoc}%
}

\begin{document}
\tableofcontents
\blinddocument
\appendix
\blinddocument
\end{document}

运行三次即可获得与我的原始答案相同的结果(见下文)。


原始答案: 以下是需要 KOMA-Script 版本 3.27 或更新版本的建议:

\documentclass[english]{scrartcl}[2019/10/13]% needs version 3.27 or newer
\usepackage{blindtext}% only for dummy text
\usepackage{babel}
\usepackage{xparse}
\usepackage{calc}

\newcommand\useprefix[2]{#1#2}
\newlength\appendixprefixwidth

\NewDocumentCommand\appendixprefixintoc{}
{%
  \setlength\appendixprefixwidth{%
    \widthof{\usekomafont{sectionentry}\appendixname~}}% measure needed additional space
  \DeclareTOCStyleEntry
    [%
      entrynumberformat=\useprefix{\appendixname~},% add the prefix before the entrynumber
      numwidth+=\appendixprefixwidth% enlarge numwidth for level section
    ]{default}{section}
  \DeclareTOCStyleEntries[%
    indent+=\appendixprefixwidth% enlarge indent for other levels
  ]{default}{subsection,subsubsection,paragraph,subparagraph}
}

\newcommand*{\appendixmore}{%
  \renewcommand*{\sectionformat}{%
    \appendixname~\thesection\autodot\enskip}%
  \renewcommand*{\sectionmarkformat}{%
    \appendixname~\thesection\autodot\enskip}%
  \addtocontents{toc}{\appendixprefixintoc}%
}

\begin{document}
\tableofcontents
\blinddocument
\appendix
\blinddocument
\end{document}

在此处输入图片描述

答案2

\documentclass[english]{scrartcl}
\usepackage{babel}
\usepackage{xparse}

\NewDocumentCommand\setappendixprefix{}
{% 
 \DeclareTOCStyleEntry[entrynumberformat=\appendixname~,dynnumwidth=true]{default}{section}
}

\newcommand*{\appendixmore}{%
   \renewcommand*{\sectionformat}{%
      \appendixname~\thesection\autodot\enskip}%
   \renewcommand*{\sectionmarkformat}{%
      \appendixname~\thesection\autodot\enskip}
   \addtocontents{toc}{\setappendixprefix}
   }


\begin{document}
\tableofcontents
 \section{A Section} ...
 \appendix
\section{A Section in the Appendix} ...
\subsection{A Subsection in the Appendix} ...
\section{Another Section in the Appendix} ...

\end{document}

在此处输入图片描述

答案3

在章节中添加“附录”:

\newcommand\useprefix[2]{#1#2}

\NewDocumentCommand\appendixprefixintoc{}
{%
  \DeclareTOCStyleEntry
    [%
      entrynumberformat=\useprefix{\appendixname~},% add the prefix before the entrynumber
      dynnumwidth
    ]{default}{chapter}
  \DeclareTOCStyleEntries[%
    dynindent
  ]{default}{chapter,subsection,subsubsection,paragraph,subparagraph}
}

\newcommand*{\appendixmore}{%
  \renewcommand*{\chapterformat}{%
    \appendixname~\thechapter\autodot\enskip}%
  \renewcommand*{\chaptermarkformat}{%
    \appendixname~\thechapter\autodot\enskip}%
  \addtocontents{toc}{\appendixprefixintoc}%
}

相关内容