考试类别:将章节名称添加到标题中

考试类别:将章节名称添加到标题中

我在网上搜索了一段时间,但还是搞不清楚该怎么做。我试图将当前部分名称添加到类中页面的页眉中,exam该类对页眉和页脚的处理略有不同。我更新了命令\thesection,并\thesubsection为部分(I、II、III、...)设置罗马数字,为子部分(A、B、C、...)设置字母。我认为这会干扰标题。有办法解决这个问题吗?

\documentclass[12pt,a4paper]{exam}

%formatting
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}

%packages
    %maths
\usepackage{amsfonts, amsmath}
    %blind text
\usepackage{lipsum}

%headers and footers
\pagestyle{headandfoot}
    %headers
    \lhead{\thesection}
    \chead{}
    \rhead{\thesubsection}
    %footers
    \lfoot{}
    \cfoot[]{Page \thepage\ of \numpages}
    \rfoot{}
    %line under head
    \runningheadrule

%sets roman numbers for sections (I, II, III, ...) alphabet for subsections (A, B, C, ...)
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\thesection.\Alph{subsection}}

%title
\author{Author} \title{Title} \date{Last updated: \today}



\begin{document} \maketitle \tableofcontents \newpage

%first section
\section{Section Name}
    \subsection{Subsection Name}
    \lipsum[3]
    
\end{document}

输出

答案1

通常\section用于\sectionmark存储部分名称,\subsection用于\subsectionmark存储子部分名称,尽管在本例中,两者都设置为不存储任何内容(\@gobble)。当它们存储时,它们通常使用\markboth\markright,但这些会延迟页面(每个)的定义。

\documentclass[12pt,a4paper]{exam}

%formatting
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}

%packages
    %maths
\usepackage{amsfonts, amsmath}
    %blind text
\usepackage{lipsum}

%headers and footers
\pagestyle{headandfoot}
    %headers
    \lhead{\leftmark}
    \chead{}
    \rhead{\rightmark}
    %footers
    \lfoot{}
    \cfoot[]{Page \thepage\ of \numpages}
    \rfoot{}
    %line under head
    \runningheadrule
    
    \def\sectionmark#1{\xdef\leftmark{\thesection\space #1}}% \markboth{\thesection\space #1}{}
    \def\subsectionmark#1{\xdef\rightmark{\thesubsection\space #1}}% \markright{\thesubsection\space #1}

%sets roman numbers for sections (I, II, III, ...) alphabet for subsections (A, B, C, ...)
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\thesection.\Alph{subsection}}

%title
\author{Author} \title{Title} \date{Last updated: \today}



\begin{document} \maketitle \tableofcontents \newpage

%first section
\section{Section Name}
    \subsection{Subsection Name}
    \lipsum[2]
    
\end{document}

相关内容