
前提: 私は fancyhdr を初めて使用します。次のファンシー スタイルを定義しました:
\lhead{}
\chead{\slshape\leftmark}
\rhead{}
\lfoot{}
\cfoot{\thepage}
\rfoot{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
各章の最初のページを除くすべてのページに、章番号と章名、上行、下行、ページ番号を正しく描画します。
そこで、プレーン スタイルを次のように再定義しました。
\fancypagestyle{plain}{
\lhead{}
\chead{}
\rhead{}
\lfoot{}
\cfoot{\thepage}
\rfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0.4pt}}
各章の最初のページに、上線、下線、ページ番号を正しく描画します (注意: プレーン スタイルでは、章番号とファンシー スタイルの名前が欠落します)
今、目次に問題があります。目次の最初のページはプレーン スタイル (章番号と名前なし) ですが、次のページはファンシー スタイル (章番号と名前あり) です。目次のすべてのページにプレーン スタイルを適用するにはどうすればよいでしょうか。
答え1
クラスを使用しているのでbook
、フロントマターのすべてがplain
ページスタイルの下にあることを意図していると推測します。
\documentclass[a4paper,oneside]{book}
\usepackage{fancyhdr}
\usepackage{etoolbox}
\usepackage{lipsum} % just for the example
\pagestyle{fancy}
\fancypagestyle{main}{%
\fancyhf{}%
\fancyhead[C]{\slshape\leftmark}%
\fancyfoot[C]{\thepage}%
\renewcommand{\headrulewidth}{0.4pt}%
\renewcommand{\footrulewidth}{0.4pt}%
}
\fancypagestyle{plain}{%
\fancyhf{}%
\fancyfoot[C]{\thepage}%
\renewcommand{\headrulewidth}{0pt}%
\renewcommand{\footrulewidth}{0.4pt}%
}
\appto\frontmatter{\pagestyle{plain}}
\appto\mainmatter{\pagestyle{main}}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
%%% fill with some mock text
\def\testsec{\section{B}\lipsum}
\def\test{\chapter{A}
\testsec
\testsec
\testsec
\testsec
\testsec
\testsec
\testsec
\testsec
\testsec
\testsec
}
\test
\test
\test
\test
\test
\test
\test
\test
\end{document}
ただし、フットルールはお勧めしません。
答え2
実際の文書の序文でこれを試してください
\usepackage{etoc}
\renewcommand{\etocaftertitlehook}{\pagestyle{plain}}
\renewcommand{\etocaftertochook}{\thispagestyle{plain}}
(上の行を編集し\pagestyle
て置き換えます)\thispagestyle
MWE:
\documentclass{book}
\usepackage{fancyhdr}
\lhead{}
\chead{\slshape\leftmark}
\rhead{}
\lfoot{}
\cfoot{\thepage}
\rfoot{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\fancypagestyle{plain}{
\lhead{}
\chead{}
\rhead{}
\lfoot{}
\cfoot{\thepage}
\rfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0.4pt}}
\usepackage{etoc}
\renewcommand{\etocaftertitlehook}{\pagestyle{plain}}
\renewcommand{\etocaftertochook}{\thispagestyle{plain}}
\begin{document}
\tableofcontents
\chapter{ONE}
\section {A}
\chapter{TW0}
\section {B}
\newcount\cnta
\loop
\chapter{\the\cnta}
\ifnum\cnta<50
\advance\cnta 1
\repeat
\end{document}