[Tex/LaTex] How to reset the page number back to 1 at every subsection

page-numbering

I have a hard time resetting the page number to 1 at the beginning of every subsection (which also starts on a new page). I've tried several things so the code might still be cluttered. Please have a look at it:

\documentclass[11pt, oneside]{article}      
\usepackage[headheight=110pt]{geometry}                     
\geometry{a4paper}                          
\usepackage{titlesec}
\usepackage{hyperref}
\usepackage{amsmath, etoolbox}
\usepackage{multicol}               
\usepackage[none]{hyphenat}         
\usepackage[document]{ragged2e}     
\usepackage{sectsty}
\setcounter{secnumdepth}{4}
\newcommand{\myparagraph}[1]{\paragraph{#1}\mbox{}\\}

% the following lines are supposed to define the page numbering

\setcounter{section}{1}
\numberwithin{page}{subsection}

\usepackage{chngcntr}
\counterwithin{page}{subsection}
\setcounter{page}{1}

\let\stdsection\subsection
\renewcommand\subsection{\newpage\stdsection} 
\renewcommand{\thepage}{\thesubsection-\arabic{page}}

\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}
\rhead{\thepage}
\begin{document}
\clearpage
\begin{multicols}{2}
\subsection{Section 1}
\subsubsection{Subsection 1.1}
\myparagraph{Introduction}
Words.
\clearpage
\myparagraph{Name}
More Words
\subsection{Subsection 1.2}
\subsection{Next Section}
\end{multicols}
\end{document}

Thank you! 🙂

Best Answer

Since you have already included etoolbox you can use the following code:

\def\rescntr{\setcounter{page}{1}}
\appto\subsection{\rescntr}

instead of your approach with \counterwithin. The code above will reset the counter as needed. Included in your MWE:

\documentclass[11pt,a4paper,oneside]{article}      
\usepackage[headheight=110pt]{geometry}
\usepackage{titlesec}
\usepackage{hyperref}
\usepackage{amsmath, etoolbox}
\usepackage{multicol}
\usepackage[document]{ragged2e}     
\usepackage{sectsty}
\setcounter{secnumdepth}{4}
\newcommand{\myparagraph}[1]{\paragraph{#1}\mbox{}\\}

% the following lines are supposed to define the page numbering

\setcounter{section}{1}
\numberwithin{page}{subsection}

\def\rescntr{\setcounter{page}{1}}
\appto\subsection{\rescntr}

\let\stdsection\subsection
\renewcommand\subsection{\newpage\stdsection} 
\renewcommand{\thepage}{\thesubsection-\arabic{page}}

\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}
\rhead{\thepage}
\begin{document}
\clearpage
\begin{multicols}{2}
\subsection{Section 1}
\subsubsection{Subsection 1.1}
\myparagraph{Introduction}
Words.
\clearpage
\myparagraph{Name}
More Words
\subsection{Subsection 1.2}
\subsection{Next Section}
\end{multicols}
\end{document}