自訂內容頁面中的標題

自訂內容頁面中的標題

在此輸入影像描述我的圖書類文件僅在 LE 和 RO 頁面上有章節標題,我也希望在內容頁面中也有相同的章節標題。我嘗試使用\makeatletter \let\@mkboth\relax \makeatother和 添加完全刪除標題\fancyhead[LE,RO]{\leftmark},但這導致目錄標題旁邊的“目錄”一詞以大寫形式出現。下面給出了 MWE,並添加了我得到的圖像:

\documentclass[a4paper,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{lipsum}% used to get dummy text
\begin{document}
\pagestyle{fancy}
\makeatletter
\let\@mkboth\relax
\makeatother
\tableofcontents%
\fancyhead[LE,RO]{\leftmark}
\cleardoublepage
\chapter{Chapter 1}
\section{Section 1.1}
\lipsum[1]% used to get dummy text
\cleardoublepage
\chapter{Chapter 2}
\section{Section 2.1}
\lipsum[2]% used to get dummy text
\chapter{Chapter 3}
\section{Section 3.1}
\lipsum[3]% used to get dummy text
\end{document}

任何指向解決方案的指針都會受到讚賞。

我需要的內容頁面的標題類型(除了第一頁)與所有章節一樣,如下圖所示:我需要的範例內容頁面,第一頁除外

答案1

編輯評論後:我想我終於明白你真正想回答的問題是什麼了。

我過去常常fancyhdr在標題中添加章節標題。然而,對於目錄的頁面,章節標題“CONTENTS”出現在標題的兩側,即也作為節標題。如何將其從標頭的一側刪除?

這有一個簡單的答案:用於\markright{}清除標題的“部分標題”部分。您可以透過將其包裝到(將其放在內容第一頁上的\addtocontents{toc}章節標題調用之後)和(將其放在目錄中的第一個“條目”處)來實現。\markboth\AtBeginDocument

\documentclass[a4paper,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{lipsum}% used to get dummy text
\AtBeginDocument{\addtocontents{toc}{\protect\markboth{\textsl{CONTENTS}}{}}} 
\begin{document}
\pagestyle{fancy}
\tableofcontents%
\cleardoublepage
\chapter{Chapter 1}
\section{Section 1.1}
\lipsum[1]% used to get dummy text
\cleardoublepage
\chapter{Chapter 2}
\section{Section 2.1}
\lipsum[2]% used to get dummy text
\chapter{Chapter 3}
\section{Section 3.1}
\lipsum[3]% used to get dummy text
\end{document}

第 2 頁的標題:在此輸入影像描述


舊答案:

在沒有任何手動幹預的情況下,目錄後續頁面的預設標題左右兩側都有大寫字母「CONTENTS」。與所有其他章節的開頭頁一樣,目錄的第一頁沒有任何標題。

\documentclass[a4paper,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{lipsum}% used to get dummy text
\begin{document}
\pagestyle{fancy}
\tableofcontents%
\cleardoublepage
\chapter{Chapter 1}
\section{Section 1.1}
\lipsum[1]% used to get dummy text
\cleardoublepage
\chapter{Chapter 2}
\section{Section 2.1}
\lipsum[2]% used to get dummy text
\chapter{Chapter 3}
\section{Section 3.1}
\lipsum[3]% used to get dummy text
\end{document}

第 2 頁的標題:在此輸入影像描述


要修改放入目錄頁標題中的內容,您必須呼叫\markboth它來覆蓋目錄標題中已放入的內容。無需破解任何其他命令來不呼叫\markboth或相關命令,因為這些巨集的目的實際上是覆蓋現有的內容。所以你真的只需要打電話\markboth 目錄的章節標題和第一個分頁符,最好是直接在章節標題之後。

靈感來自這個答案,我會將目錄的呼叫新增\markboth為第一個條目(以便在章節標題之後直接呼叫它)。為了確保它是第一個條目,您可以\AtBeginDocument在序言中使用。最小的例子:

\documentclass[a4paper,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{lipsum}% used to get dummy text
\AtBeginDocument{\addtocontents{toc}{\protect\markboth{Contents}{\textnormal{More Contents}}}} 
\begin{document}
\pagestyle{fancy}
\tableofcontents%
\cleardoublepage
\chapter{Chapter 1}
\section{Section 1.1}
\lipsum[1]% used to get dummy text
\cleardoublepage
\chapter{Chapter 2}
\section{Section 2.1}
\lipsum[2]% used to get dummy text
\chapter{Chapter 3}
\section{Section 3.1}
\lipsum[3]% used to get dummy text
\end{document}

第 2 頁的標題:在此輸入影像描述

現在您當然想要修改它,以獲得所需的標題的確切措辭和文字格式樣式。請注意,預設樣式(至少在這個最小的範例中)是斜體文本,因此您可能需要覆蓋它。

相關內容