# Page numbers in toc wrong when using chapters without new page

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. Oct 31 '18 at 10:21

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}


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}


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 *


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]