Koma 更改 TOC 部分条目的字体

Koma 更改 TOC 部分条目的字体

我遇到了一个奇怪的问题。我尝试对整个目录及其文本中的条目使用主等宽字体。但由于某种原因,它对目录中的章节条目不起作用。但它对章节本身有效。有什么想法吗?

\documentclass[twoside,11pt]{scrreprt}
     \usepackage[ngerman]{babel}
     \usepackage{xltxtra}

    \setsansfont[
        Ligatures={TeX,Common%,Rare
            },
        RawFeature=+onum;+pnum,
        SmallCapsFont={Alegreya Sans SC}
    ]{Alegreya Sans}

    \setmonofont[
    Ligatures={TeX,Common%,Rare
    },
    RawFeature=+onum;+pnum,
    ]{Anonymous Pro}

    \setromanfont[
        Scale=MatchLowercase,
        Ligatures={TeX,Common%,Rare
            },
        RawFeature=+onum;+pnum,
        SmallCapsFont={Cormorant SC},
    BoldItalicFont={Cormorant Italic}
    ]{Cormorant}

    \addtokomafont{disposition}{\ttfamily}
    \addtokomafont{title}{\rmfamily}
    \addtokomafont{titlehead}{\rmfamily}
    \addtokomafont{subtitle}{\rmfamily}
    \addtokomafont{publishers}{\sffamily}
    \addtokomafont{date}{\sffamily}
    \addtokomafont{author}{\sffamily}

    \newcommand{\ProtM}{A Male}
    \newcommand{\ProtW}{Female}
    \newcommand{\ProtO}{Others}

    \newcommand{ \HE}[1]{\section{\ProtM: #1}}
    \newcommand{\SHE}[1]{\section{\ProtW: #1}}
    \newcommand{\THEY}[1]{\section{\ProtO: #1}}

    \title{\textsc{Maintitle in rm sc}}
    \subtitle{subtitle in rm}
    \author{My name in sf}
    \date{Place, \footnote{\today} in sf}
    \publishers{\XeLaTeX in sf}

    \newcommand{\blndtxt}{Here is a bit text \dots Is here a bit text? Is the text here just a bit? A bit text is here. Text is here a for a while. Isn't it?}
\begin{document}
    \maketitle
    \tableofcontents
    \chapter{Test Chapter}
    \HE{Hello world}
    \blndtxt\blndtxt\blndtxt
    \SHE{Hello world}
    \blndtxt\blndtxt\blndtxt
    \THEY{Hello world}
    \blndtxt\blndtxt\blndtxt
    \chapter{AnotherTest Chapter}
    \HE{Bye world}
    \blndtxt\blndtxt\blndtxt
    \SHE{Bye world}
    \blndtxt\blndtxt\blndtxt
    \THEY{Bye world}
    \blndtxt\blndtxt\blndtxt
\end{document}

答案1

只有章节级别才有自己的字体元素,用于目录条目及其页码。它们使用元素disposition。因此章节条目是等宽的。

要仅更改其他部分级别的目录条目的字体,您可以在序言中使用:

\AfterTOCHead[toc]{\ttfamily}

但是条目的页码不是等宽的:

在此处输入图片描述

请注意,我已经使用了,libertine因为我没有你的字体。


使用 KOMA-Script 3.20 或更新版本,您可以用来\RedeclareSectionCommands更改条目的字体及其页码

\newcommand*\tocentryformat[1]{{\ttfamily#1}}
\RedeclareSectionCommands
  [
    tocentryformat=\tocentryformat,
    tocpagenumberformat=\tocentryformat
  ]
  {section,subsection,subsubsection,paragraph,subparagraph}

在此处输入图片描述

\documentclass[twoside,11pt]{scrreprt}[2016/05/10]
\usepackage[ngerman]{babel}
\usepackage{xltxtra}
\usepackage{libertine}

\addtokomafont{disposition}{\ttfamily}
\addtokomafont{title}{\rmfamily\scshape}% <- changed
\addtokomafont{titlehead}{\rmfamily}
\addtokomafont{subtitle}{\rmfamily}
\addtokomafont{publishers}{\sffamily}
\addtokomafont{date}{\sffamily}
\addtokomafont{author}{\sffamily}

\newcommand*\tocentryformat[1]{{\ttfamily#1}}
\RedeclareSectionCommands
  [
    tocentryformat=\tocentryformat,
    tocpagenumberformat=\tocentryformat
  ]
  {section,subsection,subsubsection,paragraph,subparagraph}


\newcommand{\ProtM}{A Male}
\newcommand{\ProtW}{Female}
\newcommand{\ProtO}{Others}

\newcommand{ \HE}[1]{\section{\ProtM: #1}}
\newcommand{\SHE}[1]{\section{\ProtW: #1}}
\newcommand{\THEY}[1]{\section{\ProtO: #1}}

\title{Maintitle in rm sc}% <- changed
\subtitle{subtitle in rm}
\author{My name in sf}
\date{Place, \footnote{\today} in sf}
\publishers{\XeLaTeX in sf}

\newcommand{\blndtxt}{%
  Here is a bit text \dots Is here a bit text?
  Is the text here just a bit?
  A bit text is here. Text is here a for a while. Isn't it?%
}
\begin{document}
\maketitle
\tableofcontents
\chapter{Test Chapter}
\HE{Hello world}
\blndtxt\blndtxt\blndtxt
\SHE{Hello world}
\blndtxt\blndtxt\blndtxt
\THEY{Hello world}
\blndtxt\blndtxt\blndtxt
\chapter{AnotherTest Chapter}
\HE{Bye world}
\blndtxt\blndtxt\blndtxt
\SHE{Bye world}
\blndtxt\blndtxt\blndtxt
\THEY{Bye world}
\blndtxt\blndtxt\blndtxt
\end{document}

答案2

你可以找到解决方案这里

只需将您的替换\tableofcontents{\renewcommand*\normalfont{\usekomafont{disposition}}\normalfont\tableofcontents}

在此处输入图片描述

相关内容