我需要使用 设置目录中编号和未编号章节的样式scrbook
,以便:
chapterprefix
编号章节采用大写形式,以破折号的形式出现chaptertitle
,例如 CHAPTER 1 --- FOO。- 未编号章节之一的摘要(英文)以斜体表示。
我的MWE
%% Preamble %%
\documentclass[12pt,a4paper,chapterprefix=true,headings=twolinechapter,oneside,]{scrbook}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{lipsum}
\usepackage{mathptmx}
% Style Table of Content.
\newcommand\chapterentrynumberformat[1]{\chapapp\ #1}
\RedeclareSectionCommand[
tocentrynumberformat=\chapterentrynumberformat,
tocnumwidth= 5em,
]{chapter}
\setkomafont{chapterentrypagenumber}{\nullfont}
\renewcommand\addchaptertocentry[2]{%
\IfArgIsEmpty{#1}
{\addtocontents{toc}
{\protect\begingroup
\protect\setkomafont{chapterentrypagenumber}{}%
\protect\KOMAoptions{chapterentrydots}%
}%
\addtocentrydefault{chapter}{}{#2}%
\addtocontents{toc}{\protect\endgroup}%
}
{\addtocentrydefault{chapter}{#1}{#2}}%
}
%% Document Parts %%
\begin{document}
\frontmatter
\pagestyle{plain}
\tableofcontents
\addchap{ABSTRAK} % Abstract in language other than English
\lipsum[1]
\addchap{ABSTRACT} % Abstract in English, must be shown italicised in ToC
\lipsum[2]
\mainmatter
\addchap{SOMESTUFFS}
\lipsum[3]
\chapter{FOO}
\section{Bar}
\lipsum[4]
\end{document}
非常感谢您的帮助。谢谢。
答案1
我会用
\usepackage{xpatch}% needed to path \addchaptertocentry
% Style Table of Content.
\setkomafont{chapterentrypagenumber}{\nullfont}
\newcommand\chapterentrynumberformat[1]{\MakeUppercase\chapapp\ #1\kern 0.25em---\kern 0.25em}
\xpatchcmd{\addchaptertocentry}
{\addtocentrydefault{chapter}{#1}{#2}}
{\IfArgIsEmpty{#1}
{\addtocontents{toc}
{\protect\begingroup
\protect\setkomafont{chapterentrypagenumber}{}%
\protect\KOMAoptions{chapterentrydots}%
}%
\addtocentrydefault{chapter}{}{\MakeUppercase{#2}}%
\addtocontents{toc}{\protect\endgroup}%
}
{\addtocentrydefault{chapter}{}{\protect\chapterentrynumberformat{#1}\MakeUppercase{#2}}}%
}{}{\PatchFailed}
根据@Schweinebacke 的建议(参见他对该问题的评论)并且\usepackage[T1]{fontenc}
:
\documentclass[
12pt,a4paper,
chapterprefix=true,% chapterprefixline does the same
headings=optiontoheadandtoc,% <- added
oneside
]{scrbook}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{lipsum}
\usepackage[T1]{fontenc}% <- added
\usepackage{mathptmx}
\usepackage{xpatch}% needed to path \addchaptertocentry
% Style Table of Content.
\setkomafont{chapterentrypagenumber}{\nullfont}
\newcommand\chapterentrynumberformat[1]{\MakeUppercase\chapapp\ #1\kern 0.25em---\kern 0.25em}
\xpatchcmd{\addchaptertocentry}
{\addtocentrydefault{chapter}{#1}{#2}}
{\IfArgIsEmpty{#1}
{\addtocontents{toc}
{\protect\begingroup
\protect\setkomafont{chapterentrypagenumber}{}%
\protect\KOMAoptions{chapterentrydots}%
}%
\addtocentrydefault{chapter}{}{\MakeUppercase{#2}}%
\addtocontents{toc}{\protect\endgroup}%
}
{\addtocentrydefault{chapter}{}{\protect\chapterentrynumberformat{#1}\MakeUppercase{#2}}}%
}{}{\PatchFailed}
%% Document Parts %%
\begin{document}
\frontmatter
\pagestyle{plain}
\tableofcontents
\addchap{ABSTRAK} % Abstract in language other than English
\lipsum[1]
\addchap[tocentry=\textit{ABSTRACT}]{ABSTRACT} % Abstract in English, must be shown italicised in ToC
\lipsum[2]
\mainmatter
\addchap{SOMESTUFFS}
\lipsum[3]
\chapter{FOO}
\section{Bar}
\lipsum[4]
\setcounter{chapter}{9}
\chapter{Chapter with two digit number}
\end{document}
结果是
更新
如果您正在加载包,hyperref
请使用命令\texorpdfstring
来避免\MakeUppercase ...ppercaseUnsupportedInPdfStrings
错误:
\documentclass[
12pt,a4paper,
chapterprefix=true,% chapterprefixline does the same
headings=optiontoheadandtoc,% <- added
oneside
]{scrbook}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{lipsum}
\usepackage[T1]{fontenc}% <- added
\usepackage{mathptmx}
\usepackage{xpatch}% needed to path \addchaptertocentry
\usepackage{hyperref}
% Style Table of Content.
\setkomafont{chapterentrypagenumber}{\nullfont}
\newcommand\chapterentrynumberformat[1]{\MakeUppercase\chapapp\ #1\kern 0.25em---\kern 0.25em}
\xpatchcmd{\addchaptertocentry}
{\addtocentrydefault{chapter}{#1}{#2}}
{\IfArgIsEmpty{#1}
{\addtocontents{toc}
{\protect\begingroup
\protect\setkomafont{chapterentrypagenumber}{}%
\protect\KOMAoptions{chapterentrydots}%
}%
\addtocentrydefault{chapter}{}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
\addtocontents{toc}{\protect\endgroup}%
}
{\addtocentrydefault{chapter}{}{\texorpdfstring{\protect\chapterentrynumberformat{#1}\MakeUppercase{#2}}{#2}}}%
}{}{\PatchFailed}
%% Document Parts %%
\begin{document}
\frontmatter
\pagestyle{plain}
\tableofcontents
\addchap{ABSTRAK} % Abstract in language other than English
\lipsum[1]
\addchap[tocentry=\textit{ABSTRACT}]{ABSTRACT} % Abstract in English, must be shown italicised in ToC
\lipsum[2]
\mainmatter
\addchap{SOMESTUFFS}
\lipsum[3]
\chapter{FOO}
\section{Bar}
\lipsum[4]
\setcounter{chapter}{9}
\chapter{Chapter with two digit number}
\end{document}
答案2
chapterprefix
我对自己的问题有部分答案,即在目录中的编号章节条目中的和之间添加破折号chaptertitle
,并将其设为大写chapterprefix
。
在我原来的 MWE 中
% Style Table of Content.
\newcommand\chapterentrynumberformat[1]{\chapapp\ #1}
\RedeclareSectionCommand[
tocentrynumberformat=\chapterentrynumberformat,
tocnumwidth= 5em,
]{chapter}
我附加\MakeUppercase
在前面\chapapp
(即打印“章节”),在破折号前后添加一些 hspace。然后我调整tocnumwidth
的属性\RedeclareSectionCommand
,使chaptertitle
不与破折号重叠。MWE 现在显示
% Style Table of Content.
\newcommand\chapterentrynumberformat[1]{\MakeUppercase\chapapp\ #1\kern 0.25em---\kern 0.25em}
\RedeclareSectionCommand[
tocentrynumberformat=\chapterentrynumberformat,
tocnumwidth= 7.5em,
]{chapter}
我仍在寻找如何将其中一个未编号章节(即摘要)斜体化的解决方案。