Fancyhead \rightmark 没有更新

Fancyhead \rightmark 没有更新

我突然遇到一个问题,fancyhead{\rightmark} 没有更新到当前章节/部分,无法找出问题所在,参见下面的代码,第 1 章的 \rightmark 为空:

\documentclass{report}

\usepackage{fancyhdr}
\usepackage{lipsum}
%\usepackage{xthesis}
%\usepackage[colorlinks=true,linkcolor=black,citecolor=red,breaklinks = true, 
%urlcolor = blue, pdftitle={Report}, pdfauthor={Author}]{hyperref}

\pagestyle{fancy}
\fancyhead[R]{} 
\fancyhead[L]{}

\begin{document}

%\cleardoublepage \phantomsection \addcontentsline{toc}{chapter}{\listfigurename}
%\addcontentsline{toc}{chapter}{\listfigurename}
%\listoffigures


\chapter*{Introduction \label{cha:Introduction}}

\newpage
\fancyhead[R]{Aims}
\section*{Aim of this Thesis \label{sec:Aim}}
\addcontentsline{toc}{section}{Aim of this Thesis}
    The aims of this thesis are:


\cleardoublepage

\fancyhead[R]{\rightmark}
\chapter{First Chapter}
\lipsum

\end{document}

输出图像

答案1

您可以使用 为非编号部分设置右侧和左侧标记\markboth{Introduction}{Aim of this Thesis}

但同时也要选择twosidereport编号章节保持相同的样式。

\chapter*{Introduction}

A b

\chapter{First Chapter} C

\documentclass[twoside]{report}

\usepackage{fancyhdr}
\usepackage{kantlipsum}

\fancyhf{}
\fancyhead[RO,LE]{\thepage}
\fancyhead[RE]{\nouppercase{\rightmark}} % section
\fancyhead[LO]{\nouppercase{\leftmark}} %chapter
\renewcommand{\headrulewidth}{0.5pt}
\pagestyle{fancy}


\begin{document}

%\cleardoublepage \phantomsection \addcontentsline{toc}{chapter}{\listfigurename}
%\addcontentsline{toc}{chapter}{\listfigurename}
%\listoffigures

\chapter*{Introduction \label{cha:Introduction}}
1.  \kant[1]

\markboth{Introduction}{Aim of this Thesis} % <<<<<<<<<<<
\section*{Aim of this Thesis \label{sec:Aim}}
\addcontentsline{toc}{section}{Aim of this Thesis}

The aims of this thesis are:

2   \kant[2-6]  

\chapter{First Chapter}
3.  \kant[3-9]

\section{Numbered section}
4,  \kant[4-8]

\end{document}

相关内容