我希望我的目录不仅显示章节的无衬线页码,还显示章节的无衬线页码。我之前(六年前)使用过以下代码,它有效。它能被识别吗,为什么现在不起作用?我假设包中有一些变化。但是,如何解决这个问题?
\documentclass[10pt,twoside,titlepage,headsepline,headings=small,BCOR=17mm]{scrbook}
\usepackage{scrlayer-scrpage} % scrpage2
\usepackage{cmap}
\usepackage{ulem}
\usepackage[utf8]{inputenc}
\usepackage[vietnamese=nohyphenation]{hyphsubst}
\usepackage[vietnamese,polish]{babel}
\usepackage[T5,T1]{fontenc}
\usepackage{longtable}
\usepackage{lmodern}
\usepackage{makeidx}
\usepackage[columns=2,itemlayout=abshang,initsep=1.8em plus 0.2em minus 0.2em]{idxlayout}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage{etoolbox}
\makeatletter
\let\old@dottedcontentsline\@dottedtocline
\def\@dottedtocline#1#2#3#4#5{\old@dottedcontentsline{#1}{#2}{#3}{#4}{\textsf{#5}}}
\makeatother
\begin{document}
\sffamily\tableofcontents\normalfont
\mainmatter
\chapter{A chapter}
\addsec{A section}
Some text is written here. What do you think of it?
\addsec{Another section}
Some text is written here. What do you think of it?
\chapter{Another chapter}
\addsec{Again a section}
Some text is written here. What do you think of it?
\addsec{And another section}
Some text is written here. What do you think of it?
\end{document}
答案1
KOMA-Script 提供\DeclareTOCStyleEntry
(在 3.20 版本中引入)和 \DeclareTOCStyleEntries
(在 3.26 版本中引入)更改条目和页码的字体设置的功能:
\DeclareTOCStyleEntries[
entryformat=\textsf,
pagenumberformat=\textsf
]{tocline}{section,subsection,subsubsection,paragraph,subparagraph,figure,table}
例子:
\documentclass[10pt,twoside,titlepage,headsepline,headings=small,BCOR=17mm]{scrbook}
\usepackage{scrlayer-scrpage}
\usepackage{cmap}
\usepackage{ulem}
\usepackage[utf8]{inputenc}
\usepackage[vietnamese=nohyphenation]{hyphsubst}
\usepackage[vietnamese,polish]{babel}
\usepackage[T5,T1]{fontenc}
\usepackage{longtable}
\usepackage{lmodern}
\usepackage{makeidx}
\usepackage[columns=2,itemlayout=abshang,initsep=1.8em plus 0.2em minus 0.2em]{idxlayout}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage{etoolbox}
\DeclareTOCStyleEntries[
entryformat=\textsf,
pagenumberformat=\textsf
]{tocline}{section,subsection,subsubsection,paragraph,subparagraph,figure,table}
\begin{document}
\tableofcontents
\mainmatter
\chapter{A chapter}
\addsec{A section}
Some text is written here. What do you think of it?
\addsec{Another section}
Some text is written here. What do you think of it?
\chapter{Another chapter}
\addsec{Again a section}
Some text is written here. What do you think of it?
\addsec{And another section}
Some text is written here. What do you think of it?
\end{document}
答案2
我认为这可以实现您想要的功能,如我对您的 MWE 的修订版本中所示,对此您表示感谢。
% tocsfprob.tex SE 578458
\documentclass[10pt,twoside,titlepage,headsepline,headings=small,BCOR=17mm]{scrbook}
\usepackage{comment} %% added
\usepackage{scrlayer-scrpage} % scrpage2
\usepackage{cmap}
\usepackage{ulem}
\usepackage[utf8]{inputenc}
\usepackage[vietnamese=nohyphenation]{hyphsubst}
\usepackage[vietnamese,polish]{babel}
\usepackage[T5,T1]{fontenc}
\usepackage{longtable}
\usepackage{lmodern}
\usepackage{makeidx}
\usepackage[columns=2,itemlayout=abshang,initsep=1.8em plus 0.2em minus 0.2em]{idxlayout}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage{etoolbox}
\begin{comment}
\makeatletter
\let\old@dottedcontentsline\@dottedtocline
\def\@dottedtocline#1#2#3#4#5{\old@dottedcontentsline{#1}{#2}{#3}{#4}{\textsf{#5}}}
\makeatother
\end{comment}
\usepackage{tocloft} %% added plus next 2 lines
\renewcommand{\cftchappagefont}{\sffamily}
\renewcommand{\cftsecpagefont}{\sffamily}
\begin{document}
\sffamily\tableofcontents\normalfont
\mainmatter
\chapter{A chapter}
\addsec{A section}
Some text is written here. What do you think of it?
\addsec{Another section}
Some text is written here. What do you think of it?
\chapter{Another chapter}
\addsec{Again a section}
Some text is written here. What do you think of it?
\addsec{And another section}
Some text is written here. What do you think of it?
\end{document}