
私の問題を説明するために、まず私の MWE から始めましょう。
\documentclass[a4paper,10pt]{book}
\usepackage{lipsum}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{extramarks}
\makeatletter
\renewcommand\chapter{\@startsection%
{chapter}{0}{0mm}%
{2.5\baselineskip}{1.5\baselineskip}%
{\centering\normalfont\large\scshape
}%
}
\makeatother
\newcommand{\mychap}[1]{
\chapter*{#1}
\markboth{#1}{#1}}
\renewcommand{\sectionmark}{}
\renewcommand{\chaptermark}{\markboth{\thechapter}}
\pagestyle{fancy}
\fancyhf{}
\fancyhead{}
\fancyhead[LE]{{\thepage}}
\fancyhead[RE]{ {\itshape \nouppercase \firstleftmark}}%higher level \scshape \MakeUppercase
\fancyhead[LO]{ {\itshape \nouppercase \lastrightmark}}
\fancyhead[RO]{ {\thepage}} %odd page
\begin{document}
\mychap{one}
\lipsum
\mychap{two}
aaa
\mychap{five halves}
\mychap{three}
\lipsum
\mychap{fourth}
\lipsum[5]
\mychap{five}
d
\end{document}
次の点に注意してください:
- 章をセクションとして扱いたい(改ページなし、シンプルなタイトル)
- ヘッダーに章の名前を入れたい
これらの機能を利用することができました
しかし
私も欲しいです
- ヘッダーに奇数私が欲しいページ最後ページに表示される章(これは を使用すると機能するようです
\lastrightmark
) - ヘッダーに平不要なページ初めページの冒頭に章があるが、現在章、つまりページをめくりながら読んでいる章です。
私の例では
- 第 2 章はページ 1 とページ 2 の間の改ページの後に始まるため、ページ 2 には「1」を入れたいと思います。
- 第 5 章はページ 3 とページ 4 の間の改ページ後に始まるため、ページ 4 には「4」と入力したいと思います。
どうすればこれを入手できますか?
答え1
\extramarks
これらのヘッダーは、 を設定し、次のように使用することで実現できます。
\newcommand{\mychap}[1]{%
\chapter*{#1}%
\markboth{#1}{#1}%
\extramarks{#1}{#1}}
\fancyhead[RE]{\textit{\MakeLowercase{\firstxmark}}}
\fancyhead[LO]{\textit{\MakeLowercase{\lastxmark}}}
したがって、サンプルのようなドキュメントでは、one' in the heading page 2 and
要求どおりにページ 4 の見出しに 4` が表示されます。
\documentclass[a4paper,10pt]{book}
\usepackage{lipsum}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{extramarks}
\makeatletter
\renewcommand\chapter{\@startsection%
{chapter}{0}{0mm}%
{2.5\baselineskip}{1.5\baselineskip}%
{\centering\normalfont\large\scshape
}%
}
\makeatother
\newcommand{\mychap}[1]{%
\chapter*{#1}%
\markboth{#1}{#1}%
\extramarks{#1}{#1}}
\pagestyle{fancy}
\fancyhf{}
\fancyhead{}
\fancyhead[LE]{\thepage}
\fancyhead[RE]{\textit{\MakeLowercase{\firstxmark}}}
\fancyhead[LO]{\textit{\MakeLowercase{\lastxmark}}}
\fancyhead[RO]{\thepage}
\begin{document}
\mychap{One}
\lipsum
\mychap{Two}
Two words.
\mychap{Two and a half}
\mychap{Three}
\lipsum
\mychap{Four}
\lipsum[5]
\mychap{Five}
A sentence of five words.
\end{document}
両方とも\markboth
そして \extramarks
正しい値を取得する必要があります (これは の「バグ」に依存している可能性がありますextramarks
)。また、標準マークを使用しなくなったため、見出しテキストを目的の形式に強制する必要があります\MakeLowercase
。