但

為了解釋我的問題,讓我從我的 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}

請注意:

  1. 我想將章節視為部分(沒有分頁符,簡單的標題)
  2. 在標題中我想要章節的名稱

我能夠獲得這些功能

我也想得到

  1. 在標題上奇怪的我想要的頁面最後的頁面中出現的章節(這似乎可以使用\lastrightmark
  2. 在標題上甚至我不想要的頁面第一的章節從該頁開始,但是目前的Chapter,也就是我翻頁時正在閱讀的章節。

在我的例子中

  1. 在第 2 頁上,我希望有“一”,因為第二章是在第 1 頁和第 2 頁之間的分頁符號之後開始的;
  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`。

第1頁

第2頁

第3頁

第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將標題文字強制為所需的形式,因為我們現在不再使用標準標記。

相關內容