
為了解釋我的問題,讓我從我的 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
) - 在標題上甚至我不想要的頁面第一的章節從該頁開始,但是目前的Chapter,也就是我翻頁時正在閱讀的章節。
在我的例子中
- 在第 2 頁上,我希望有“一”,因為第二章是在第 1 頁和第 2 頁之間的分頁符號之後開始的;
- 在第 4 頁上,我希望有“四”,因為第五章是在第 3 頁和第 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
需要獲得正確的值(這可能是依賴“bug” extramarks
)。此外,我還習慣\MakeLowercase
將標題文字強制為所需的形式,因為我們現在不再使用標準標記。