如何将每个小节的页码重置回 1?

如何将每个小节的页码重置回 1?

我很难将每个小节开头的页码重置为 1(这也从新页面开始)。我尝试了几种方法,所以代码可能仍然很混乱。请看一下:

\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}

谢谢你! :-)

答案1

由于您已经包含,因此etoolbox您可以使用以下代码:

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

而不是使用 的方法\counterwithin。上面的代码将根据需要重置计数器。包含在您的 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}

相关内容