私のブック クラス ドキュメントには、LE ページと RO ページにのみ章タイトルがあり、目次ページにも同じタイトルを付けたいと考えています。 と を\makeatletter \let\@mkboth\relax \makeatother
追加してヘッダーを完全に削除してみました\fancyhead[LE,RO]{\leftmark}
が、その結果、目次のタイトルの隣に Contents という単語が大文字で表示されてしまいました。以下に 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}
古い回答:
手動による介入がなければ、目次の以降のページのデフォルトのヘッダーには、左右に大文字で「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}
目次のページのヘッダーに何を入れるかを変更するには、 を呼び出して、\markboth
すでに目次のキャプションに入力されているものを上書きする必要があります。これら\markboth
のマクロの目的は、すでに入力されているものを上書きすることであるため、他のコマンドや関連コマンドを呼び出さないようにする必要はありません。したがって、実際に必要なのは を呼び出すことだけです。\markboth
後目次の章見出しと前に最初のページ区切り、つまり理想的には章の見出しの直後。
に触発されたこの答え、最初のエントリとして 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{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}
もちろん、必要なヘッダーの正確な文言とテキスト書式スタイルを設定するために、これを変更する必要があります。デフォルトのスタイル (少なくともこの最小限の例では) は斜体のテキストであるため、それを上書きする必要がある場合があることに注意してください。