fancyhdr を使用して、「第 1 章」やセクション番号なしでヘッダーに章とセクションのタイトルを交互に表示する方法

fancyhdr を使用して、「第 1 章」やセクション番号なしでヘッダーに章とセクションのタイトルを交互に表示する方法

これは重複しているように見えるかもしれませんが、そうではないと思います。私が求めているのは、交互に表示されるページのヘッダーに、章とセクションのタイトルを斜体で表示し、その前に「第 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}

ここに画像の説明を入力してください

関連情報