# Header with scrpage2 disappears on "last page" when using subfiles package

When I put two or more TeX files together with the subfiles package, the header disappears on the last pages of the included files. Why is that?

The Root.tex file:

 \documentclass[a4paper]{scrartcl}
\usepackage{subfiles}
\usepackage{scrpage2}
\usepackage[ngerman]{babel}
\usepackage{blindtext}

\begin{document}
\subfile{test1.tex}\newpage
\subfile{test2.tex}
\end{document}


The used subfiles have the same content and are named test1.tex and test2.tex:

 \documentclass[Root.tex]{subfiles}

\begin{document}
\Blindtext
\Blindtext
\end{document}

• Take a look, whether standalone could be a better choice instead of subfiles. Oct 18 '13 at 0:49

After nobody answered here, I have asked Markus Kohm on komascript.de (in German: “Kopfzeile verschwindet mit scrpage2 mit subfiles Paket”).

As I understood to keep it local, insert an \clearpage at the end of each subfile will solve the problem.

He also mentioned an global solution which is the following code (insert in root preamble):

\makeatletter
\renewcommand{\skip@preamble}{%
\expandafter\def\expandafter\document\expandafter{%
\expandafter\endgroup
\expandafter\def\expandafter\document\expandafter{\document}%
}%
\expandafter\def\expandafter\enddocument\expandafter{%
\expandafter\endinput
\expandafter\def\expandafter\enddocument\expandafter{\enddocument}%
\begingroup
\edef\@currenvir{document}%
}%
\renewcommand{\documentclass}[2][subfiles]{}%
}
\renewcommand*{\subfile}[1]{\skip@preamble\input{#1}}
\makeatother

• You should also mention the consequence of this ungrouping/globalization: Former local settings of subfiles will turn general. Oct 18 '13 at 0:59
• And perhaps change to Community Wiki (edit answer, look at he end), because it’s Markus’ work? Oct 18 '13 at 1:02
• Of course it's Markus' work. What is it about, the community wiki? Oct 18 '13 at 7:11
• It’s a special post category, meant for easier collaborating, but with the effect, to one does not earn reputation from such posts, see Privileges - edit community wiki. Oct 18 '13 at 21:35