![考试类别:将章节名称添加到标题中](https://linux22.com/image/460402/%E8%80%83%E8%AF%95%E7%B1%BB%E5%88%AB%EF%BC%9A%E5%B0%86%E7%AB%A0%E8%8A%82%E5%90%8D%E7%A7%B0%E6%B7%BB%E5%8A%A0%E5%88%B0%E6%A0%87%E9%A2%98%E4%B8%AD.png)
我在网上搜索了一段时间,但还是搞不清楚该怎么做。我试图将当前部分名称添加到类中页面的页眉中,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}