我原创了两个命令:
\newcommand{\headremark}[1]{%
\newpage
\lhead{#1}
}
\makeatletter
\renewcommand{\chapter}{
\if@openright\cleardoublepage\else\clearpage\fi
\global\@topnum\z@
\secdef\@chapter\@schapter}
\makeatother
然后我在我的论文中使用它们,就像。
\begin{abstract}
\pagenumbering{roman}
aaa
\end{abstract}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\headremark{Acknowledgments}
\chapter*{Acknowledgments}
aaa
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tableofcontents
\newpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Introduction}
但是“Acknowledgment”显示在目录和第 1 章的页眉中。我猜“headremark”命令在后续章节中也会继续。我该如何避免这种情况并显示“CONTENTS”或“Chapter 1 INTRODUCTION”?
我附上了可比较的最小例子:
\documentclass[12pt,
a4paper,
one side,
one column,
titlepage,
final,
]{report}
\usepackage[dvipdfmx]{graphicx}
\usepackage{fancyhdr}
\usepackage{latexsym}
\usepackage{framed}
\setlength{\oddsidemargin}{10pt}
\setlength{\evensidemargin}{10pt}
\setlength{\topmargin}{0pt}
\setlength{\headheight}{20pt}
\setlength{\headsep}{20pt}
\setlength{\topskip}{12pt}
\setlength{\textheight}{623.5pt}
\setlength{\textwidth}{432.5pt}
\setlength{\footskip}{25pt}
\makeatletter
\renewcommand{\chapter}{
\if@openright\cleardoublepage\else\clearpage\fi
\global\@topnum\z@
\secdef\@chapter\@schapter}
\makeatother
\pagestyle{headings}
\pagestyle{myheadings}
\pagestyle{fancy}
\renewcommand{\headwidth}{432.5pt}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\renewcommand{\plainheadrulewidth}{0.4pt}
\renewcommand{\plainfootrulewidth}{0.4pt}
\lhead{\leftmark}
\chead{}
\rhead{\thepage}
\lfoot{}
\cfoot{}
\rfoot{Dept.}
\newcommand{\headremark}[1]{%
\newpage
\lhead{#1}%
}
\title{AAA}
\author{ \\ \\ \\ \\NAME\\}
\date{Dec 2023}
\begin{document}
\maketitle
\pagenumbering{roman}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{abstract}
\pagenumbering{roman}
aaa
\end{abstract}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\headremark{Acknowledgments}
\chapter*{Acknowledgments}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tableofcontents
\newpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Introduction}
aaa
\end{document}
答案1
不要直接设置页眉/页脚的内容。您不想硬编码,Acknowledgements
就像您不想硬编码页面一样3
。就像您使用一样\thepage
,使用 LaTeX 的一个或一些mark
s。不可否认,这些比 更棘手\thepage
,但fancyhdr
的文档有很大帮助,而且单面文档的复杂性较少,所以应该不会太糟糕。
我强烈建议考虑使用geometry
and titling
(或类似符号)。手动设置每个维度容易出错,而且不灵活。用强制换行符设置标题近乎野蛮。
\documentclass[12pt,
a4paper,
one side,
one column,
titlepage,
final,
]{report}
\usepackage[dvipdfmx]{graphicx}
\usepackage{fancyhdr}
\usepackage{latexsym}
\usepackage{framed}
\usepackage{etoolbox}
% do you have something against geometry?
% this is extremely error prone.
\setlength{\oddsidemargin}{10pt}
\setlength{\evensidemargin}{10pt}
\setlength{\topmargin}{0pt}
\setlength{\headheight}{20pt}
\setlength{\headsep}{20pt}
\setlength{\topskip}{12pt}
\setlength{\textheight}{623.5pt}
\setlength{\textwidth}{432.5pt}
\setlength{\footskip}{25pt}
\pagestyle{fancy}
\renewcommand{\headwidth}{432.5pt}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\renewcommand{\plainheadrulewidth}{0.4pt}
\renewcommand{\plainfootrulewidth}{0.4pt}
\fancyhf{}
\fancyhf[lh]{\leftmark}
\fancyhf[rh]{\thepage}
\fancyhf[rf]{Dept.}
\fancypagestyle{plain}{%
\pagestyle{fancy}%
}
\renewcommand{\chaptermark}[1]{\markboth{#1}{#1}}
\patchcmd{\tableofcontents}{\MakeUppercase}{}{\typeout{Patching succeeded.}}{\typeout{Patching failed.}}
\title{AAA}
\author{ \\ \\ \\ \\NAME\\}% this is a pretty bad way to do this - consider using the titling package
\date{Dec 2023}
\begin{document}
\maketitle
\pagenumbering{roman}
\begin{abstract}
aaa
\end{abstract}
\chapter*{Acknowledgments}
\markboth{Acknowledgements}{Acknowledgements}
\tableofcontents
\chapter{Introduction}
\pagenumbering{arabic}
aaa
\end{document}
以上内容假设您不需要大写标题。如果需要,则无需重新定义\chaptermark
或修补\tableofcontents
。
我认为您是被迫使用这种风格的,这是由于惯常的制度性疯狂,所以我不会指出印刷方面的缺陷,我相信您已经非常清楚了。