章节编号和标题

章节编号和标题

我有一个文档(scrbook类),我希望其中某些章节不从新页面开始。因此,我定义了以下内容:

%define a chapter that does not add space at the top of the page
\usepackage{etoolbox}
\makeatletter
\let\chapterNoSpace\chapter 
\patchcmd\chapterNoSpace{\if@openright\cleardoublepage\else\clearpage\fi}{}{}{}
\patchcmd{\chapterNoSpace}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}
\makeatother

这几乎满足了我的要求。但是,有三个问题:

  1. 我需要在任何\chapterNoSpace命令之前添加一个新段落,否则它会将章节直接放在与最后一段文本同一行。

  2. 在章节开始的页面上,我缺少标题。

  3. 如果该命令与新页面一致,则前一页上的页眉会丢失,并且\vskip页眉前会出现伪像,看起来很奇怪。

我在下面添加了一个最小脚本。

\documentclass[11pt, a4paper, twoside, openany]{scrbook}
%headers
\usepackage{fancyhdr}\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\thepart.\ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thepart.\thechapter.\ #1}}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[LO]{\rightmark}
\fancyhead[RE]{\leftmark}
\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrulewidth}{0pt}}

%Define a chapter that doesn't start on new page
\usepackage{etoolbox}
\makeatletter
\let\chapterNoSpace\chapter 
\patchcmd\chapterNoSpace{\if@openright\cleardoublepage\else\clearpage\fi}{}{}{}
%\renewcommand*{\chapterheadstartvskip}{\vspace*{1cm}}
%\patchcmd\chapterNoSpace{\chapterheadstartvskip}{\vspace{1cm}}{}{}
\patchcmd{\chapterNoSpace}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}
\makeatother
\begin{document}
\part{Part 1}
\chapter{Normal chapter 1}
text text text text text text
\chapter{Normal chapter 2}
text text text text text
\chapterNoSpace{Chapter on same page 1}
text text text

\chapterNoSpace{Chapter on same page 2 with line brake above}
text text text
\chapter{Normal chapter 3}
text text text

\end{document}

有什么建议么?

答案1

更新:KOMA-Script 3.16 版可能更好

\documentclass[open=any]{scrbook}
%headers
\usepackage[automark,headsepline]{scrlayer-scrpage}
\clearpairofpagestyles
\ohead*{\pagemark}
\ihead{\headmark}
\addtokomafont{pagehead}{\normalfont}

%Define a chapter that doesn't start on new page
\usepackage{etoolbox}
\makeatletter
\let\chapterNoSpace\chapter 
\patchcmd\chapterNoSpace{\if@openright\cleardoublepage\else\clearpage\fi}{\par\vspace{\baselineskip}}{}{}
\patchcmd{\chapterNoSpace}{\thispagestyle{\chapterpagestyle}}{}{}{}
\makeatother

\RedeclareSectionCommand[beforeskip=0pt]{chapter}

\usepackage{blindtext}% dummy text
\usepackage{showframe}% to show the page layout

\begin{document}
\part{Part 1}
\chapter{Normal chapter 1}
\blindtext[20]
\chapter{Normal chapter 2}
text
\chapterNoSpace{Chapter on same page 1}
\Blindtext[3]
\chapterNoSpace{Chapter on same page 2 with line brake above}
\blindtext
\chapter{Normal chapter 3}
\blindtext
\blinddocument
\end{document}

在此处输入图片描述


旧答案:将您的补丁更改为

\patchcmd\chapterNoSpace{\if@openright\cleardoublepage\else\clearpage\fi}{\par}{}{}
\patchcmd{\chapterNoSpace}{\thispagestyle{\chapterpagestyle}}{\thispagestyle{fancy}}{}{}

将解决 1. 和 2.

如果你想要全部章节在页面顶部添加较少的空间,您可以使用

\renewcommand*\chapterheadstartvskip{\vspace*{0pt}}

代码:

\documentclass[openany]{scrbook}
%headers
\usepackage{fancyhdr}\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\thepart.\ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thepart.\thechapter.\ #1}}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[LO]{\rightmark}
\fancyhead[RE]{\leftmark}
\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrulewidth}{0pt}}

%Define a chapter that doesn't start on new page
\usepackage{etoolbox}
\makeatletter
\let\chapterNoSpace\chapter 
\patchcmd\chapterNoSpace{\if@openright\cleardoublepage\else\clearpage\fi}{\par}{}{}
\patchcmd{\chapterNoSpace}{\thispagestyle{\chapterpagestyle}}{\thispagestyle{fancy}}{}{}
%
\renewcommand*\chapterheadstartvskip{\vspace*{0pt}}
\makeatother
\usepackage{blindtext}% dummy text

\begin{document}
\part{Part 1}
\chapter{Normal chapter 1}
\blindtext[20]
\chapter{Normal chapter 2}
text
\chapterNoSpace{Chapter on same page 1}
\Blindtext[3]
\chapterNoSpace{Chapter on same page 2 with line brake above}
\blindtext
\chapter{Normal chapter 3}
\blindtext
\blinddocument
\end{document}

请注意,不建议fancyhdr与 KOMA-Script 类一起使用。请尝试使用scrlayer-scrpage

相关内容