我已经实现了这样的自定义子部分:
\renewcommand\thesubsection{Question \arabic{section}.\arabic{subsection}}
我想清除每个小节之前的页面,所以我添加了这个
\usepackage{titlesec}
\newcommand{\subsectionbreak}{\clearpage}
问题是我还想通过这样做在正确的标题中显示子部分:
\pagestyle{fancy}
\rhead{\thesubsection}
问题:页眉中的子部分为 1.2,而页面上的子部分为 1.1
我也试过
\let\oldsection\section
\renewcommand\section{\clearpage\oldsection}
但这只是给我带来了一个错误......
编辑:这是显示错误的示例的完整代码:
\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}
\rhead{\thesubsection}
\lhead{}
\begin{document}
\section{}
\subsection{}
Subsec 1
\subsection{}
Subsec 2
\end{document}
答案1
我强烈建议使用合适的question/answer
包而不是使用\subsection
这种方式,但无论如何,这里有一种方法可以做到。
我还增加了number width
目录中的间距,否则Question 1.2.
内容会在目录的可能用途中重叠打印点。
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{etoolbox}
\usepackage{tocloft}
\renewcommand\thesection{Section \arabic{section}}
\renewcommand\thesubsection{Question \arabic{section}.\arabic{subsection}}
\addtolength{\cftsubsecnumwidth}{30pt}% Increase the 'number width'
\pretocmd{\subsection}{\clearpage}{}{} % Prepend `\subsection` with `\clearpage from now on...
\pagestyle{fancy}
\rhead{\ifnum\value{subsection} > 0\thesubsection\fi}
\lhead{}
\begin{document}
\tableofcontents
\clearpage
\section{}
\subsection{}
Subsec 1
\subsection{}
Subsec 2
\end{document}
更新
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{tocloft}
\renewcommand\thesection{Section \arabic{section}}
\renewcommand\thesubsection{Question \arabic{section}.\arabic{subsection}}
\addtolength{\cftsubsecnumwidth}{30pt}% Increase the 'number width'
\makeatletter
\let\orig@subsection\subsection
\renewcommand{\subsection}{%
\ifnum\value{subsection} > 0 %
\clearpage%
\fi%
\orig@subsection%
}
\makeatother
\pagestyle{fancy}
\rhead{\ifnum\value{subsection} > 0\thesubsection\fi}
\lhead{}
\begin{document}
\tableofcontents
\clearpage
\section{}
\subsection{}
Subsec 1
\subsection{}
Subsec 2
\end{document}