# Starting a new chapter without heading: References point to wrong, previous (sub-)sections

I need to include a bunch of PDFs as files after and before other regular chapters. I want each PDF to be a numbered chapter, be included in the toc, and to appear in the header-line (of fancyhdr), but not the actual 'Chapter X. A fancy chapter' to be printed, since that would print the 'Chapter X', then a blank page, then the pdfs.

All of this works fine with a solution I found on another question ( Start a new chapter without heading )

\documentclass{scrbook} %report}
\usepackage{hyperref}

\makeatletter
\newcommand{\unchapter}[1]{%
\begingroup
\chapter{#1}
\endgroup
}
\makeatother

\begin{document}
\tableofcontents

\chapter{Regular}\label{sec:regular}
\section{Something}\label{sec:something}
Text

Text\newpage

References: \\
Regular: \ref{sec:regular}\\
Something: \ref{sec:something}\\
\end{document}


However, I face a problem when I want to refer to the chapter, since that then refers to the last (sub-)section. I.e. the example references of the last chapter look like this:

References:
Regular: 1
Something: 1.1
Regular again: 3


The links also lead to section 1.1. So I assume makechapterhead is somehow necessary for the references to work, but I couldn't find what it does.

I did find \refstepcounter{chapter}, but that only increments Regular again: 3 to 4, so it seems the counter is correctly incremented by the \unchapter, but the reference just doesn't know there was a change?

I also tried sprinkling some clearpage, new page, chaptermark, all over it to no avail.

• I suspect hyperref patches something in chapter that got deleted. Try using \phantomsection (page 40). Nov 24, 2022 at 19:35

This code gives the right result. (without the \begingroup and \endgroup)

\documentclass{scrbook} %report}
\usepackage{hyperref}

\makeatletter
\newcommand{\unchapter}[1]{% changed <<<<<<<<<<<<
%\begingroup
\chapter{#1}
%\endgroup
}
\makeatother

\begin{document}
\tableofcontents

\chapter{Regular}\label{sec:regular}
\section{Something}\label{sec:something}
Text

Text\newpage

References:

Regular: \ref{sec:regular}

Something: \ref{sec:something}