修改目录中的附录条目(KOMA-Script)

修改目录中的附录条目(KOMA-Script)

有关目录中附录条目的四个问题:

  1. 如您在附图中看到的,我希望每个附录条目的页码不是粗体,而是普通字体(就像章节的字体一样)。只有附录本身(以带有“附录”字样的页面开头)应该使用粗体,因为它被视为章节。

  2. 我希望每个子附录条目(附录 1、附录 2,...)都有这些点(再次像在章节条目中一样)。

  3. 如果子附录条目有多行,我对您在图片中看到的缩进不满意。我想按照附图所示的方式排列它。

  4. 有没有办法减少子附录条目之间的间距?(类似于章节、小节等的行为)

在此处输入图片描述

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

答案1

另一种解决方案。

附录目录

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

答案2

正如@Johannes 在评论中所说:每个附录都应该是自己的一章。更改目录中章节条目的行为毫无用处。

您可以定义\appendixsection类似于\section使用以下命令:

\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

然后,您可以使用以下方式格式化目录中的条目

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

在此处输入图片描述

以及正文中的标题

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

在此处输入图片描述

代码:

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

相关内容