0

Because I didn't want chapters on a new page I wrote them like {\let\clearpage\relax \chapter{Foo}} as suggested in another thread. Unfortunately this messes up the page numbers for chapters in the toc, when a chapter is (by coincidence) starting on a new page. I have created a minimal working example with the problem:

\documentclass[]{scrreprt}
\usepackage{lipsum}

\begin{document}
    \tableofcontents

    \chapter{Foo}
    \lipsum[1-4]

    {\let\clearpage\relax \chapter{Bar}}
    \section{Barsub}
    \lipsum[5]
\end{document}

As you can see the page number for chapter "Bar" is 2 instead of 3. Note however, that the page number of the section is correct.

I've tried to fix this by adding a \pagebreak before the chapter, but it changed the layout (in a more complex document). Doing \setcounter{page}{3} before the chapter "Bar" doesn't do the trick either.

How can I fix the page numbers without changing the layout? If necessary I'm willing to deploy "dirty" workarounds where I increase the page number manually.

  • Welcome to TeX.SX! Note that this problem only appears if the page break happens to be exactly before the chapter heading. – Jasper Habicht Oct 31 '18 at 10:21
1

Change style for chapters to style=section:

It seems that chapters should behave like sections:

\documentclass{scrreprt}
\usepackage{lipsum}
\RedeclareSectionCommand[
  style=section,
  indent=0pt
]{chapter}

\begin{document}
\tableofcontents

\cleardoublepage
\chapter{Foo}
\lipsum[1-4]

\chapter{Bar}
\section{Barsub}
\lipsum[5]

\chapter{Barfoo}
\section{Barfoosub}
\lipsum[6]
\end{document}

enter image description here

But note that there is no vertical space before the TOC heading and before chapter »Foo«.


Declare a new sectioning command:

Maybe you want an additional sectioning command on the chapter level but with style=section:

\documentclass{scrreprt}[2017/09/07]
\usepackage{lipsum}

\DeclareNewSectionCommand[
  style=chapter,
  level=\chapternumdepth,
  tocstyle=chapter,
  tocindent=0pt,
  tocnumwidth=1.5em
]{mychapter}% clone \chapter as \mychapter

\RedeclareSectionCommand[
  style=section,
  indent=0pt
]{mychapter}% change the style to section

\makeatletter
\let\c@mychapter\c@chapter% use the same counter for chapter and mychapter
\def\cl@mychapter{\cl@chapter}% use the same reset list as chapter
\makeatother

\begin{document}
\tableofcontents

\chapter{Foo}
\lipsum[1-4]

\mychapter{Bar}
\section{Barsub}
\lipsum[5]

\mychapter{Barfoo}
\section{Barfoosub}
\lipsum[6]
\end{document}

enter image description here

If page style headings is used in the document, you have to add \let\mychaptermark\chaptermark right after the first \pagestyle{headings}:

\pagestyle{headings}
\let\mychaptermark\chaptermark

Or with package scrlayer-scrpage:

\usepackage[automark]{scrlayer-scrpage}
\automark*{mychapter}% note the *
| improve this answer | |
1

If you redefine a core command like \clearpage then you can expect things to break, the chapter heading code in the class you are using is written assuming it comes top of page. The code below is similarly wrong but works here. The correct way would be to redesign the chapter heading code for an in-page heading, but if you just want a quick patch this would work.

Simpler really would be to use an article class rather than report and have top level headings being \section which typically do not force a page break.

\documentclass[]{scrreprt}
\usepackage{lipsum}


\begin{document}
    \tableofcontents

    \chapter{Foo}
    \lipsum[1-4]

    {\noindent\parbox[t]{\textwidth}{\chapter{Bar}}}\csname @afterheading\endcsname
    \section{Barsub}
    \lipsum[5]
\end{document}
| improve this answer | |
  • Thanks for the insight into LaTeX! I will choose the document class more careful in the future. I just took the first document class that seemed to work here. – J. Doe Oct 31 '18 at 13:07
  • @J.Doe ask yourself how many published books you see with chapters (as opposed to sections) starting mid page..... (by the way you were correct to accept the other answer which shows the komascript declarations to redefine chapter, I'll leave this answer here though as it is closer to the spirit of what you tried, a patch (that would work for any documentclass) to force chapters not to be on a new page. – David Carlisle Oct 31 '18 at 13:47

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.