3

I’m using the scrbook class but removing the pagebreaks that precede each chapter using a patchcmd I copy-and-pasted from here without understanding it.

When this leads to a chapter heading being exactly at the beginning of a page, the table of contents lists the chapter as being at (the end of) the previous page.

The following MWE demonstrates this: The ToC lists Second Chapter as being on page 1.

\documentclass[]{scrbook}

% remove pre-chapter pagebreak as per https://tex.stackexchange.com/a/24067
\usepackage{etoolbox}
\makeatletter
\patchcmd{\scr@startchapter}{\if@openright\cleardoublepage\else\clearpage\fi}{}{}{}
\makeatother

\begin{document}

\tableofcontents

\chapter{First Chapter}
Lorem ipsum
\vspace{11cm}

This page is pretty full.

\chapter{Second Chapter}
More lorem ipsum

\end{document}

How do I fix the page number in the ToC? I don’t mind if the solution is hacky.

Extra questions: Is it a terrible abuse of scrbook to use it this way? Is there a better way to remove the pagebreaks?

tjanson
  • 135
  • This isn't really surprising. I expect the code assumes it is on the correct page because, why wouldn't it be? It just started a fresh one! But if you've stopped it starting a fresh one, without doing anything to make sure it is on the right page, obviously it's not going to be a safe assumption any longer. Dare I ask why you don't use sections instead of chapters? – cfr Jul 29 '18 at 22:22
  • No reason, other than that I think of them as chapters (the actual document is ~30 pages). I’m blissfully unaware of LaTeX’s internals. – tjanson Jul 29 '18 at 23:01

1 Answers1

4

Avoid patching internal commands. You could use \RedeclareSectionCommand to change the style to section for \chapter:

\documentclass[]{scrbook}

\RedeclareSectionCommand[
  style=section,
  indent=0pt
]{chapter}

\begin{document}
\tableofcontents
\chapter{First Chapter}
Lorem ipsum
\par\vspace{11cm}
This page is pretty full.
\chapter{Second Chapter}
More lorem ipsum
\end{document}

Result:

enter image description here

esdd
  • 85,675
  • This is a very good example, because it shows, how mighty \RedeclareSectionCommandis. A quick search for this command here provides about 300 results. If I had time, I'd put the best of them into an article for TeXnische Komödie or elsewhere. – Keks Dose Jul 30 '18 at 09:38