如何使用 fancyhdr 在標題中取得交替的章節標題,而不使用「第 1 章」或章節編號

如何使用 fancyhdr 在標題中取得交替的章節標題,而不使用「第 1 章」或章節編號

這可能看起來像重複的,但我認為不是。我想要的是交替頁面的標題中的章節標題以斜體顯示,而前面沒有“第一章”或章節號。我已經設法到達那裡,但我無法設法在奇數頁上獲取章節標題(沒有章節編號),而不使章節標題從偶數頁的標題中完全消失。

我用來嘗試刪除「第 1 章」和「1.1」的命令分別是:

\renewcommand{\chaptermark}[1]{\markboth{#1}{}}

\renewcommand{\sectionmark}[1]{\markboth{#1}{}}

這是一個 MWE:

\documentclass[12pt, twoside]{report}

\usepackage{lipsum}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{} %clears header
\fancyhead[CE]{\nouppercase{\textit{\leftmark}}} %puts chapter title on even page in lower-case italics
\fancyhead[CO]{\nouppercase{\textit{\rightmark}}} %puts section title on odd page in lower-case italics
\renewcommand{\headrulewidth}{0pt} %gets rid of line
\renewcommand{\chaptermark}[1]{\markboth{#1}{}} %gets rid of chapter number
\renewcommand{\sectionmark}[1]{\markboth{#1}{}} %gets rid of section number

\begin{document}

\chapter{Off we go}

\section{Introduction}

\lipsum[1-7]

\section{Key Point}

\lipsum[7-10]


\end{document}

我懷疑這與 \markboth 位有關,但我無法弄清楚!謝謝!

答案1

你必須使用

\renewcommand{\sectionmark}[1]{\markright{#1}}

例子:

\documentclass[12pt, twoside]{report}
\usepackage{lipsum}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{} %clears header
\fancyhead[CE]{\nouppercase{\textit{\leftmark}}} %puts chapter title on even page in lower-case italics
\fancyhead[CO]{\nouppercase{\textit{\rightmark}}} %puts section title on odd page in lower-case italics
\renewcommand{\headrulewidth}{0pt} %gets rid of line
\renewcommand{\chaptermark}[1]{\markboth{#1}{}} %gets rid of chapter number
\renewcommand{\sectionmark}[1]{\markright{#1}} %gets rid of section number

\begin{document}
\chapter{Off we go}
\section{Introduction}
\lipsum[1-7]
\section{Key Point}
\lipsum[7-10]
\end{document}

在此輸入影像描述

相關內容