# Subsection not aligned with header subsection when using clearpage before subsection

I have implemented a custom subsection like this:

\renewcommand\thesubsection{Question \arabic{section}.\arabic{subsection}}


And I would like to clear the page before each subsection so I added this

\usepackage{titlesec}
\newcommand{\subsectionbreak}{\clearpage}


The problem is that I also would like to show the subsection in the right header by doing this:

\pagestyle{fancy}


Problem: Subsection in header is 1.2 when subsection on page is 1.1

I also tried

\let\oldsection\section
\renewcommand\section{\clearpage\oldsection}


But that just threw me an error...

EDIT: This is the full code of an example that shows the error:

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}

\usepackage{titlesec}
\newcommand{\subsectionbreak}{\clearpage}

\renewcommand\thesection{Section \arabic{section}}
\renewcommand\thesubsection{Question \arabic{section}.\arabic{subsection}}

\pagestyle{fancy}

\begin{document}

\section{}

\subsection{}
Subsec 1
\subsection{}
Subsec 2

\end{document}

• Welcome to TeX.SX! Fragments of code aren't really useful. Please post the minimal document that shows the error! – user31729 Dec 15 '15 at 11:51
• Ok now I updated it with a minimum not working example – vikeri Dec 15 '15 at 12:00
• Using a redefinition of \thesubsection will screw up the ToC – user31729 Dec 15 '15 at 12:04

I strongly suggest to use a proper question/answer package instead of using \subsection this way, but here's a way to do it anyway.

I've additionally increased the number width spacing in the toc, otherwise the Question 1.2. stuff would be overprinting the dots in a possible usage of the ToC.

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{etoolbox}
\usepackage{tocloft}

\renewcommand\thesection{Section \arabic{section}}
\renewcommand\thesubsection{Question \arabic{section}.\arabic{subsection}}

\pretocmd{\subsection}{\clearpage}{}{} % Prepend \subsection with \clearpage from now on...
\pagestyle{fancy}

\begin{document}
\tableofcontents

\clearpage
\section{}

\subsection{}
Subsec 1
\subsection{}
Subsec 2

\end{document}


Update

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{tocloft}

\renewcommand\thesection{Section \arabic{section}}
\renewcommand\thesubsection{Question \arabic{section}.\arabic{subsection}}

\makeatletter
\let\orig@subsection\subsection

\renewcommand{\subsection}{%
\ifnum\value{subsection} > 0 %
\clearpage%
\fi%
\orig@subsection%
}
\makeatother

\pagestyle{fancy}

\begin{document}
\tableofcontents

\clearpage
\section{}

\subsection{}
Subsec 1
\subsection{}
Subsec 2

\end{document}

• Ok great! It works apart from one thing, I do not want the section to have a page break before the first subsection. Could that be fixed? And then I do not understand etoolbox or tocloft? – vikeri Dec 15 '15 at 13:11
• @vikeri: tocloft is helpful for the ToC appearance, but etoolbox` isn't needed really. I can fix – user31729 Dec 15 '15 at 15:14
• @vikeri: See the update please (at the bottom!) – user31729 Dec 15 '15 at 15:18
• Great stuff, now it works perfectly! – vikeri Dec 15 '15 at 15:32