我有一个有点复杂的序言(因为我想要特定的美学效果),因此我使用了scrpage2
带有book
文档类的包。一切都运行良好,直到我引入了一个未编号的章节(“简介”)。这导致简介页面的标题显示为“目录”。
为了纠正这个问题,我采取了以下修复方法:
\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}
\thispagestyle{empty}
\renewcommand*{\chaptermarkformat}{}
\chaptermark{Introduction}
\lipsum[1-20]
这很好用。但我想将书的其余部分的章节号恢复到标题中。下面是一个 MWE,我曾尝试使用它renewcommand{\chaptermark}
来恢复章节号,但在尝试了相当多可能的解决方案后,我仍然无法正确完成...它只是一直显示章节名称。
我希望第 0 章的标题为“简介”,而不是“第 0 章:简介”。但是,如何才能进入Chapter 1: Another Chapter
标题,而不仅仅是Another Chapter
?
\documentclass[11pt,oneside]{book}
\usepackage{lipsum} % just for testing
%% preamble based on http://www.khirevich.com/latex %%
\usepackage[DIV=14,BCOR=2mm,headinclude=true,footinclude=false]{typearea}
\usepackage[T1]{fontenc}
\usepackage{charter}
\usepackage[expert]{mathdesign}
% Change chapter title font to sans-serif
\usepackage{sectsty}
\chapterfont{\usefont{T1}{qhv}{b}{n}\selectfont\huge}
\usepackage{graphicx}
\usepackage{titlesec}
\usepackage[titles]{tocloft}
\usepackage[activate={true, % activate protrusion
nocompatibility % activate expansion
},
final, % enable microtype (disable: "draft")
tracking=true, % activate tracking
kerning=true, % activate kerning
spacing=true, % activate spacing
factor=1100, % add 10% to protrusion (default: 1000)
stretch=10,shrink=10] % reduce streching/shrinking (default: 20/20)
{microtype}
\microtypecontext{spacing=nonfrench}
\usepackage[nodayofweek]{datetime}
\usepackage[automark,headsepline,nouppercase]{scrpage2}
\pagestyle{scrheadings}
\clearscrheadings
\automark[chapter]{chapter}
% below, define header for beginning of chapter and "normal" pages
\ohead[\leftmark ~$\vert$ \pagemark]{\leftmark ~$\vert$ \pagemark}
\renewcommand*{\headfont}{}
\DeclareMathVersion{mathchartertext}
\SetSymbolFont{letters}{mathchartertext}{OML}{mdbch}{m}{n}
\titleformat{\section}[hang]
{\usefont{T1}{bch}{b}{n}\selectfont} % format: \usefont{encoding}{family}{series}{shape}
{} % label
{0em} % sep between label and title
{\hspace{-0.4pt}
\Large \thesection\hspace{0.6em}
} % before code
[] % after code
\titleformat{\chapter}[display] % shape
{\usefont{T1}{qhv}{b}{n}\selectfont\huge} % format: sans-serif
{\chaptertitlename\ \thechapter} % label
{20pt} % sep
{\Huge}[\vspace{2ex}\titlerule] % before code
\begin{document}
\maketitle
\clearpage
\tableofcontents{\thispagestyle{empty}}
\clearpage
\mainmatter
\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}
\thispagestyle{empty}
\renewcommand*{\chaptermarkformat}{}
\chaptermark{Introduction}
\lipsum[1-20]
\chapter{Another Chapter}
\thispagestyle{empty}
\renewcommand{\chaptermark}[1]{%
\markboth{Chapter \thechapter{}: #1}{Chapter \thechapter{}: #1}%
}
\lipsum[1-20]
\backmatter
\end{document}
笔记:大部分前言对于重现我遇到的问题来说并不是必需的。但我将这些内容包含在 MWE 中,以便人们理解为什么我尝试以这种方式做事,而不是简单地使用scrbook
Koma-script 中的文档类。
答案1
您似乎想要在整个文档中进行连续编号(我喜欢这样,在前言中使用罗马数字在古代是合理的,但现在没有必要了)。
因此只需重新定义\frontmatter
并\mainmatter
执行您需要的操作。
对于章节起始页没有页码的情况,请修改\chapter
而不是每次都发布(如果需要两页或更多页,则\thispagestyle{empty}
不行)。\tableofcontents
最后,不要sectsty
一起加载titlesec
。
\documentclass[11pt,oneside]{book}
\usepackage{lipsum} % just for testing
%% preamble based on http://www.khirevich.com/latex %%
\usepackage[DIV=14,BCOR=2mm,headinclude=true,footinclude=false]{typearea}
\usepackage[T1]{fontenc}
\usepackage{charter}
\usepackage[expert]{mathdesign}
\usepackage{graphicx}
\usepackage{etoolbox}
\usepackage{titlesec}
\usepackage[titles]{tocloft}
\usepackage[activate={true, % activate protrusion
nocompatibility % activate expansion
},
final, % enable microtype (disable: "draft")
tracking=true, % activate tracking
kerning=true, % activate kerning
spacing=true, % activate spacing
factor=1100, % add 10% to protrusion (default: 1000)
stretch=10,shrink=10] % reduce streching/shrinking (default: 20/20)
{microtype}
\microtypecontext{spacing=nonfrench}
\usepackage[nodayofweek]{datetime}
\usepackage[automark,headsepline,nouppercase]{scrpage2}
\pagestyle{scrheadings}
\clearscrheadings
\automark[chapter]{chapter}
% below, define header for beginning of chapter and "normal" pages
\ohead[\leftmark ~$\vert$ \pagemark]{\leftmark ~$\vert$ \pagemark}
\renewcommand*{\headfont}{}
\DeclareMathVersion{mathchartertext}
\SetSymbolFont{letters}{mathchartertext}{OML}{mdbch}{m}{n}
\titleformat{\section}[hang]
{\usefont{T1}{bch}{b}{n}\selectfont} % format: \usefont{encoding}{family}{series}{shape}
{} % label
{0em} % sep between label and title
{\hspace{-0.4pt}
\Large \thesection\hspace{0.6em}
} % before code
[] % after code
\titleformat{\chapter}[display] % shape
{\usefont{T1}{qhv}{b}{n}\selectfont\huge} % format: sans-serif
{\chaptertitlename\ \thechapter} % label
{20pt} % sep
{\Huge}[\vspace{2ex}\titlerule] % before code
\makeatletter
% make \frontmatter and \mainmatter not to reset the numbering
\renewcommand{\frontmatter}{\cleardoublepage\@mainmatterfalse}
\renewcommand{\mainmatter}{\cleardoublepage\@mainmattertrue}
% issue \thispagestyle{empty} instead of \thispagestyle{plain}
% when starting a chapter (needs etoolbox)
\patchcmd{\chapter}{plain}{empty} % empty page style in the chapter starting pages
\makeatother
\begin{document}
\frontmatter
\title{Thesis}
\author{A. Uthor}
\maketitle
\tableofcontents
\chapter{Introduction}
\lipsum[1-20]
\mainmatter
\chapter{Another Chapter}
\lipsum[1-20]
\backmatter
\end{document}
答案2
scrpage2
要使用包或其后继包更改标题中章节编号的布局,scrlayer-scrpage
您可以重新定义\chaptermarkformat
。
这里建议使用scrbook
和scrlayer-scrpage
(的后继scrpage2
),但不使用包sectsty
、titlesec
和tocloft
。
\documentclass[oneside,
DIV=14,BCOR=2mm,headinclude=true,footinclude=false,
chapterprefix
]{scrbook}
\usepackage{lipsum} % just for testing
%% preamble based on http://www.khirevich.com/latex %%
\usepackage[T1]{fontenc}
\usepackage{charter}
\usepackage[expert]{mathdesign}
\DeclareMathVersion{mathchartertext}
\SetSymbolFont{letters}{mathchartertext}{OML}{mdbch}{m}{n}
\usepackage{graphicx}
\usepackage[activate={true, % activate protrusion
nocompatibility % activate expansion
},
final, % enable microtype (disable: "draft")
tracking=true, % activate tracking
kerning=true, % activate kerning
spacing=true, % activate spacing
factor=1100, % add 10% to protrusion (default: 1000)
stretch=10,shrink=10] % reduce streching/shrinking (default: 20/20)
{microtype}
\microtypecontext{spacing=nonfrench}
\usepackage[nodayofweek]{datetime}
\usepackage[headsepline]{scrlayer-scrpage}
\automark[chapter]{chapter}
\clearpairofpagestyles
\ohead*{\leftmark ~$\vert$ \pagemark}
\renewcommand*{\chaptermarkformat}{\chapapp\ \thechapter:\enskip}
\setkomafont{pagehead}{\normalfont\normalsize\upshape}
\renewcommand\chapterpagestyle{empty}
\setkomafont{disposition}{\usefont{T1}{qhv}{b}{n}\selectfont}
\RedeclareSectionCommand[font=\Large]{section}
\renewcommand\sectionformat{\hspace{-.4pt}\ \thesection\hspace{.6em}}
\RedeclareSectionCommand[
beforeskip=4.6\baselineskip plus \parskip,
innerskip=20pt,
afterskip=2.725\baselineskip plus.115\baselineskip minus .192\baselineskip,
font=\Huge,
prefixfont=\huge
]{chapter}
% rule after chapter
\usepackage{etoolbox}
\preto\chapterheadendvskip{%
{\usekomafont{chapter}\vspace{2ex}\noindent\rule{\textwidth}{.4pt}}\par}
\begin{document}
\title{Title}
\author{Name}
\maketitle
\tableofcontents
\mainmatter
\addchap{Introduction}
\lipsum[1-10]
\chapter{Another Chapter}
\section{A section}
\lipsum[1-20]
\end{document}
结果:
使用book
,您titlesec
还scrpage2
可以重新定义\chaptermarkformat
以获得标题中所需的布局。
\renewcommand*{\chaptermarkformat}{\chaptername{} \thechapter:\enskip}
要获取页眉中未编号的章节,请使用
\chapter*{Introduction}
\markboth{Introduction}{Introduction}
代码:
\documentclass[11pt,oneside]{book}
\usepackage{lipsum} % just for testing
%% preamble based on http://www.khirevich.com/latex %%
\usepackage[DIV=14,BCOR=2mm,headinclude=true,footinclude=false]{typearea}
\usepackage[T1]{fontenc}
\usepackage{charter}
\usepackage[expert]{mathdesign}
\usepackage{graphicx}
\usepackage{titlesec}
\usepackage[titles]{tocloft}
\usepackage[activate={true, % activate protrusion
nocompatibility % activate expansion
},
final, % enable microtype (disable: "draft")
tracking=true, % activate tracking
kerning=true, % activate kerning
spacing=true, % activate spacing
factor=1100, % add 10% to protrusion (default: 1000)
stretch=10,shrink=10] % reduce streching/shrinking (default: 20/20)
{microtype}
\microtypecontext{spacing=nonfrench}
\usepackage[nodayofweek]{datetime}
\usepackage[automark,headsepline,nouppercase]{scrpage2}
\pagestyle{scrheadings}
\clearscrheadings
\automark[chapter]{chapter}
% below, define header for beginning of chapter and "normal" pages
\ohead[\leftmark ~$\vert$ \pagemark]{\leftmark ~$\vert$ \pagemark}
\renewcommand*{\chaptermarkformat}{\chaptername{} \thechapter:\enskip}
\renewcommand*{\headfont}{}
\DeclareMathVersion{mathchartertext}
\SetSymbolFont{letters}{mathchartertext}{OML}{mdbch}{m}{n}
\titleformat{\section}[hang]
{\usefont{T1}{bch}{b}{n}\selectfont} % format: \usefont{encoding}{family}{series}{shape}
{} % label
{0em} % sep between label and title
{\hspace{-0.4pt}
\Large \thesection\hspace{0.6em}
} % before code
[] % after code
\titleformat{\chapter}[display] % shape
{\usefont{T1}{qhv}{b}{n}\selectfont\huge} % format: sans-serif
{\chaptertitlename\ \thechapter} % label
{20pt} % sep
{\Huge}[\vspace{2ex}\titlerule] % before code
\begin{document}
\title{Title}
\author{Name}
\maketitle
\clearpage
\tableofcontents{\thispagestyle{empty}}
\clearpage
\mainmatter
\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}
\markboth{Introduction}{Introduction}
\thispagestyle{empty}
\lipsum[1-20]
\chapter{Another Chapter}
\thispagestyle{empty}
\section{A section}
\lipsum[1-20]
\end{document}
请注意,这scrpage2
已被弃用。因此我建议使用 ist 后继scrlayer-scrpage
\usepackage[headsepline,markcase=noupper,forceoverwrite]{scrlayer-scrpage}
\automark[chapter]{chapter}
\clearpairofpagestyles
\ohead*{\leftmark ~$\vert$ \pagemark}
\renewcommand*{\chaptermarkformat}{\chaptername{} \thechapter:\enskip}
\setkomafont{pagehead}{\normalfont\normalsize\upshape}
该选项forceoverwrite
是必需的,因为titlesec
还定义了命令\newpagestyle
和\renewpagestyle
。