1

I have a document (scrbook class), in which I want some chapters not to start on a new page. I therefore defined the following:

%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

This does nearly what I want. However, there are three problems:

  1. I need to add a new paragraph before any \chapterNoSpace command, or it will put the chapter directly on the same line as the last text.

  2. On the page where the chapter starts, I am missing my headers.

  3. If the command coincides with a new page, the headers are missing on the page before and there is a spurious \vskip before the heading, which looks odd.

I added a minimal script below.

\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}

Any suggestions?

  • An example of code is definitely needed, from \documentclass to \end{document} – egreg Jun 4 '14 at 8:58
  • \documentclass[openany]{scrbook} should also do, without redefinition of \chapter, however, for all chapters then... – user31729 Jun 4 '14 at 9:49
  • openany will not do the trick. That just makes sure the chapters can start on a lefthand page. – user1638145 Jun 5 '14 at 9:09
  • Chapters start on a new page. Otherwise they are no chapters, but sections. Full stop. – Keks Dose Feb 27 '15 at 13:10
2

Update: Maybe better with KOMA-Script version 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}

enter image description here


Old answer: Changing your patch to

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

will solve 1. und 2.

If you want that all chapters adding less space as normal at the top of the page you can use

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

Code:

\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}

Note that it is not recommanded to use fancyhdr together with KOMA-Script classes. Try scrlayer-scrpage instead.

  • Why \renewcommand*\chapterheadstartvskip{\vspace*{-\topskip}} and not \renewcommand*\chapterheadstartvskip{\vspace*{0pt}} or even \renewcommand*\chapterheadstartvskip{}? I still don't control how \topskip works. – Manuel Jun 5 '14 at 10:10
  • 1
    @ Manuel I have changed my code because if \renewcommand*\chapterheadstartvskip{\vspace*{0pt}} then in the patch is only \par needed. But there are now additional 11pt space above a chapter starting on a new page. \topskip is the distance from the top of the text body to the first baseline and the chapter starts not on this first line. – esdd Jun 5 '14 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.