Fancyhdr:目录标题

Fancyhdr:目录标题

我的硕士论文的目录长达三页。页眉定义为。

\setlength{\headheight}{15.2pt}
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markright{#1}{}}
\renewcommand{\subsectionmark}[1]{}
\fancyhead[R]{\itshape{My name here.}}

这对全部部分(包括 LoF、LoT)都适用。它在左侧标题中打印不带数字的部分名称,在右侧标题中打印我的名字。

现在有一个问题。在目录的第一页和第三页上,左侧标题是“目录”。但是在第二页上,标题是“内容”。有什么建议可以解决这个问题吗?我也想在第二页上显示“目录”。

目录包含如下内容:

\newpage
\markright{Table of Contents}
\tableofcontents
\markright{Table of Contents}

因此显然第一个\markright负责第一页的页眉,第二个\markright负责第三页的页眉。

编辑:下面包含一个最小的例子。

\documentclass[a4paper, oneside, 11pt]{article}

\usepackage[a4paper, left=2.5cm, right=2cm, top=3cm, bottom=3cm]{geometry}
\usepackage{fancyhdr}
\usepackage[utf8]{inputenc}
\usepackage[onehalfspacing]{setspace}

\usepackage{titlesec}
\titlespacing*{\section}{0pt}{0pt}{20pt}[0pt]

\usepackage[titles]{tocloft}
\renewcommand{\cftsecfont}{\bfseries}

\renewcommand{\footrulewidth}{0.4pt}


% Header
\setlength{\headheight}{15.2pt}
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markright{#1}{}}
\renewcommand{\subsectionmark}[1]{}
\fancyhead[R]{\itshape{My name here}}


\begin{document}

\pagenumbering{Roman}
\markright{Table of Contents}
\tableofcontents
\addtocontents{toc}{~\hfill\textbf{Page}\par}                   
\markright{Table of Contents}

\newpage
\pagenumbering{arabic}
\section{Introduction}
    \subsection{Subsection 1}
    \subsection{Subsection 2}
    \subsection{Subsection 3}
    \subsection{Subsection 4}
    \subsection{Subsection 5}

\newpage
\section{Study Site}
    \subsection{Subsection 1}
    \subsection{Subsection 2}
    \subsection{Subsection 3}
    \subsection{Subsection 4}

\newpage
\section{Data}
    \subsection{Subsection 1}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
    \subsection{Subsection 2}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
        \subsubsection{Subsubsection 3}
        \subsubsection{Subsubsection 4}
    \subsection{Subsection 3}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}

\newpage
\section{Methods}
    \subsection{Subsection 1}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
        \subsubsection{Subsubsection 3}
    \subsection{Subsection 2}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
        \subsubsection{Subsubsection 3}
        \subsubsection{Subsubsection 4}
    \subsection{Subsection 3}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
        \subsubsection{Subsubsection 3}
    \subsection{Subsection 4}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
        \subsubsection{Subsubsection 3}
    \subsection{Subsection 5}

\newpage
\section{Results}
    \subsection{Subsection 1}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
        \subsubsection{Subsubsection 3}
        \subsubsection{Subsubsection 4}
    \subsection{Subsection 2}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
        \subsubsection{Subsubsection 3}
        \subsubsection{Subsubsection 4}
    \subsection{Subsection 3}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
    \subsection{Subsection 4}
    \subsection{Subsection 5}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}

\newpage
\section{Discussion}
    \subsection{Subsection 1}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
        \subsubsection{Subsubsection 3}
        \subsubsection{Subsubsection 4}
    \subsection{Subsection 2}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
        \subsubsection{Subsubsection 3}
    \subsection{Subsection 3}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2}
    \subsection{Subsection 4}
        \subsubsection{Subsubsection 1}
        \subsubsection{Subsubsection 2} 
    \subsection{Subsection 5}
    \subsection{Subsection 6}               
    \subsection{Subsection 7}

\newpage
\section{Conclusions}
    \subsection{Subsection 1}
    \subsection{Subsection 2}

\end{document}

第 1 页

第二页

答案1

尝试这个

\makeatletter\let\@mkboth\@gobbletwo\makeatother
\tableofcontents
\makeatletter\let\@mkboth\markboth\makeatother

在此处输入图片描述

相关内容