问题描述
我想创建一个页脚样式,该样式将显示在除包含\part
标题和其背面页面的页面之外的所有页面上(此异常不是问题,因为它可以正常工作)。因此,我在序言中添加了以下代码:
\clearscrheadfoot
\lefoot{\pagemark\quad\textsc{\headmark}}
\rofoot{\textsc{\headmark}\quad\pagemark}
\pagestyle{scrheadings}
\renewcommand*{\chapterpagestyle}{scrheadings}
实际问题是,每个奇数页都只显示页码,不显示章节标题。偶数页的页脚没有问题。
我想指出的是,我正在使用xelatex
并且目前正在尝试 KOMA-Script。
最小工作示例
\documentclass[10pt, chapterprefix=false, twoside]{scrbook}
% Packages
\usepackage[a4paper, top=1in, bottom=1in, right=1in, left=1in, portrait]{geometry}
\usepackage{fontspec} % For font definition
\usepackage{scrlayer-scrpage} % For headers and footers (must be loaded before `titlesec`); also, in KomaScript, this is used instead of `titleps`
\usepackage{titlesec} % For custom paragraph style of headings
\usepackage{lipsum} % For Lorem Ipsum
% Global font family
\setmainfont{Libertinus Serif}
\setsansfont{Libertinus Sans}
\addtokomafont{disposition}{\rmfamily}
% Global paragraph and line settings
\setlength{\parindent}{0em} % Set paragraph indentation
\setlength{\parskip}{0.08in} % Paragraph spacing
\renewcommand{\baselinestretch}{1.0} % Line \expandafter\selectlanguage\expandafter{\cvlang}
% Part title format
\titleformat{\part}{\Huge\scshape\bfseries\centering}{}{0em}{}%
% Chapter title format
\titleclass{\chapter}{straight}% For starting a chapter without page break
\titleformat{\chapter}[block]
{\titlerule[1pt]\addvspace{0pt}\Large\scshape\bfseries\centering}
{\thesection\enspace}{0pt}{}[\vspace{2pt}{\titlerule[1pt]}]
\titlespacing{\chapter}%
{0mm}% How much of \titlerule line to remove from left
{8mm}% Before \titlerule
{0mm}% After \titlerule
\renewcommand*{\chaptermarkformat}{}% This is to get rid of the chapter number
% Headers and footers
\clearscrheadfoot
\lefoot{\pagemark\quad\textsc{\headmark}}
\rofoot{\textsc{\headmark}\quad\pagemark}
\pagestyle{scrheadings}
\renewcommand*{\chapterpagestyle}{scrheadings}
\begin{document}
\part*{Test Part}
\chapter*{Test Chapter or Whatever}%
\chaptermark{Test Chapter}%
\lipsum[1-14]
\chapter*{Another Chapter to test}%
\chaptermark{Another Chapter}%
\lipsum[15-21]
\end{document}
答案1
通常在一页上显示章节标题,在另一页上显示 KOMA-Script 中的节标题。
要改变这一点,只需添加
\automark[chapter]{chapter} % <============== usually \automark[section]{chapter}
在你的序言中。
完整代码如下mwe.tex
:
\documentclass[10pt, chapterprefix=false, twoside]{scrbook}
% Packages
\usepackage[a4paper, top=1in, bottom=1in, right=1in, left=1in, portrait]{geometry}
\usepackage{fontspec} % For font definition
\usepackage{scrlayer-scrpage} % For headers and footers (must be loaded before `titlesec`); also, in KomaScript, this is used instead of `titleps`
\usepackage{titlesec} % For custom paragraph style of headings
\usepackage{lipsum} % For Lorem Ipsum
% Global font family
\setmainfont{Libertinus Serif}
\setsansfont{Libertinus Sans}
\addtokomafont{disposition}{\rmfamily}
% Global paragraph and line settings
\setlength{\parindent}{0em} % Set paragraph indentation
\setlength{\parskip}{0.08in} % Paragraph spacing
\renewcommand{\baselinestretch}{1.0} % Line \expandafter\selectlanguage\expandafter{\cvlang}
% Part title format
\titleformat{\part}{\Huge\scshape\bfseries\centering}{}{0em}{}%
% Chapter title format
\titleclass{\chapter}{straight}% For starting a chapter without page break
\titleformat{\chapter}[block]
{\titlerule[1pt]\addvspace{0pt}\Large\scshape\bfseries\centering}
{\thesection\enspace}{0pt}{}[\vspace{2pt}{\titlerule[1pt]}]
\titlespacing{\chapter}%
{0mm}% How much of \titlerule line to remove from left
{8mm}% Before \titlerule
{0mm}% After \titlerule
\renewcommand*{\chaptermarkformat}{}% This is to get rid of the chapter number
% Headers and footers
\clearscrheadfoot
\automark[chapter]{chapter} % <=========================================
\lefoot{\pagemark\quad\textsc{\headmark}}
\rofoot{\textsc{\headmark}\quad\pagemark}
\pagestyle{scrheadings}
\renewcommand*{\chapterpagestyle}{scrheadings}
\begin{document}
\part*{Test Part}
\chapter*{Test Chapter or Whatever}%
\chaptermark{Test Chapter}%
\lipsum[1-14]
\chapter*{Another Chapter to test}%
\chaptermark{Another Chapter}%
\lipsum[15-21]
\end{document}
您将获得最终的 pdf:
请注意文件中收到的警告mwe.log
:
Class scrbook Warning: Usage of package `titlesec' together (scrbook) with a KOMA-Script class is not recommended. (scrbook) I'd suggest to use the package only (scrbook) if you really need it, because it breaks several (scrbook) KOMA-Script features, i.e., option `headings' and (scrbook) the extended optional argument of the section (scrbook) commands. (scrbook) Nevertheless, using requested (scrbook) package `titlesec' on input line 10.
答案2
您还可以使用\automark{chapter}
和 并替换\headmark
。\leftmark
如果同一页上有多个章节开始,则最后一章将在奇数页上设置页脚标记。
\documentclass[10pt,
headings=optiontohead% <- added
]{scrbook}
% Packages
\usepackage[margin=1in]{geometry}
\usepackage{fontspec}
\usepackage{scrlayer-scrpage}% sets page style scrheadings automatically
\usepackage{lipsum}% only for dummy text
% Global font family
\setmainfont{Libertinus Serif}
\setsansfont{Libertinus Sans}
\addtokomafont{disposition}{\rmfamily}
% Global paragraph and line settings
\setparsizes{0pt}{0.08in}{0pt plus 1fil}
% Part title format
\addtokomafont{disposition}{\rmfamily}
\addtokomafont{part}{\Huge\scshape}
% Chapter title format
\RedeclareSectionCommand[
style=section,
beforeskip=\dimexpr8mm-\parskip\relax,
afterskip=-\parskip,
indent=0pt,
font=\Large\scshape,
afterindent=false,
runin=false
]{chapter}
\let\originalsectionlinesformat\sectionlinesformat
\renewcommand\sectionlinesformat[4]{%
\ifstr{#1}{chapter}
{\parbox[b]{\textwidth}{%
\titlerule\par%
\centering #3#4\par\kern-.75\ht\strutbox
\titlerule%
}}
{\originalsectionlinesformat{#1}{#2}{#3}{#4}}% original definition for other sectioning levels
}
\newcommand\titlerule[1][1pt]{\rule{\textwidth}{#1}}
% Headers and footers
\clearpairofpagestyles% <- replaces deprecated command
\automark{chapter}
\lefoot{\pagemark\quad\textsc{\leftmark}}
\rofoot{\textsc{\leftmark}\quad\pagemark}
\begin{document}
\addpart*{Test Part}
\addchap[Test Chapter]{Test Chapter or Whatever}
\lipsum[1-14]
\addchap[Another Chapter]{Another Chapter to test}
\lipsum[15-21]
\end{document}
结果: