章节编号 (\thesection) 和名称具有下一页的值

章节编号 (\thesection) 和名称具有下一页的值

我已经自定义了标题来显示章节编号和章节名称。

但是:(a)我的页眉中的章节编号(\thesection)经常与下一页的值一起显示。(b)章节中第一页的章节名称需要手动设置。

在下面的示例代码中,(a)1-3 页的章节编号显示下一页的章节编号。(b)此外,第一页的章节名称需要用 手动设置\markright,否则会显示为空文本。

顺便说一句,我假设我的所有章节都是从奇数页开始的。(我目前使用 手动执行此操作\ensuredoublepage,但当然可以修改\chapter命令。)

这个问题似乎源于分页、分段和写页眉(带有章节编号/名称)的时间。有什么简单的方法可以解决这个问题?

请注意,示例代码看起来很长(为了填充演示此效果所需的多页),但实际上非常简单。为了理解问题,只有命令之前的代码\chapter很重要,问题也一定在那里。

\documentclass{memoir}

\makeoddhead{myheadings}{\textit{\rightmark}}{}{\textit{\thesection} {\ } -- {\ } \thepage}
\makeevenhead{myheadings}{\thepage {\ \ } -- {\ \ }\textit{\thesection}}{}{\textit{\leftmark}}
\makeheadrule{myheadings}{\textwidth}{\normalrulethickness}

\makepagestyle{chapter}
\makeoddhead{chapter}{\textit{\rightmark}}{}{\textit{\thesection} {\ } -- {\ } \thepage}
\makeheadrule{chapter}{\textwidth}{\normalrulethickness}

\begin{document}

\pagestyle{myheadings}
  \renewcommand{\chaptermark}[1]{\markboth{#1}{}}
  \renewcommand{\sectionmark}[1]{\markright{#1}}

\markright{Section one (Without this macro, there'd be no text here!)}

\chapter{The only chapter}

This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text. This is introductory text.


\section{Section one}

This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section.

This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section. This is the first section.


\section{Section two}

This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section. This is the second section. This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section. This is the second section. This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section. This is the second section. This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section.

This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section. This is the second section. This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section. This is the second section. This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section. This is the second section. This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section.

This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section. This is the second section. This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section. This is the second section. This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section. This is the second section. This is the second section. This is the second section. This is the second section. This is the second section.This is the second section. This is the second section.

\section{Section three}

This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section. This is the third section. This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section. This is the third section. This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section. This is the third section. This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section.

This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section. This is the third section. This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section. This is the third section. This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section. This is the third section. This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section.

This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section. This is the third section. This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section. This is the third section. This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section. This is the third section. This is the third section. This is the third section. This is the third section. This is the third section.This is the third section. This is the third section.

\section{Section four}

This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section.

This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section.

This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section. This is the fourth section.This is the fourth section. This is the fourth section.

\end{document}

答案1

好的,忘记我之前的回答;-) 我现在发现这个文件,在 1.3 中提供了很好的信息。

第一个问题是,你正在使用\thesectionin \makeoddhead(eg)。正如你自己怀疑的那样,这是在错误的时间展开的。如果你将它放入某个\*mark命令中,它就会起作用。

第二个问题是,你把章节名称放进去,\leftmark但你却\rightmark在章节的第一页使用。正如上面引用的文件所说,\leftmark来自最后的定义和\rightmark第一的页面上的定义。不幸的是,没有\markleft。因此,为了保留后续页面的章节名称,将其放入\leftmark,然后仅用于\markright章节编号就可以了。只有现在在第一页上,包含第一个定义,它是中\rightmark的空定义。\markboth\chaptermark

为了避免这种情况。我建议保存章节名称,然后将其重新发布到\rightmark。以下方法可以实现这一点,即在标题中交替显示章节和部分名称。请注意,如果章节从偶数页开始,则需要进行一些额外的调整...

\documentclass{memoir}

\usepackage{extramarks}

\makepagestyle{myheadings}
\makeoddhead{myheadings}{\textit{\leftmark}}{}{\textit{\rightmark} {\ } -- {\ } \thepage}
\makeevenhead{myheadings}{\thepage {\ \ } -- {\ \ }\textit{\rightmark}}{}{\textit{\cchapter}}
\makeheadrule{myheadings}{\textwidth}{\normalrulethickness}

\makepagestyle{chapter}
\makeoddhead{chapter}{\textit{\leftmark}}{}{\textit{\lastrightmark} {\ } -- {\ } \thepage}
\makeheadrule{chapter}{\textwidth}{\normalrulethickness}

\renewcommand\chaptermark[1]{\markboth{#1}{}\def\cchapter{#1}}
\renewcommand\sectionmark[1]{\markboth{#1}{\thesection}}
\pagestyle{myheadings}
\begin{document}
...

答案2

您可以为正确的标记提供更多结构:

\documentclass{memoir}

\makeatletter
\makeoddhead{myheadings}
  {{\let\decide\@secondoftwo\itshape\rightmark}}
  {}
  {{\let\decide\@firstoftwo\itshape\rightmark}\quad--\quad\thepage}
\makeevenhead{myheadings}
  {\thepage\quad--\quad{\let\decide\@firstoftwo\itshape\rightmark}}
  {}
  {\itshape\leftmark}
\makeheadrule{myheadings}{\textwidth}{\normalrulethickness}

\makepagestyle{chapter}
\makeoddhead{chapter}
  {{\let\decide\@secondoftwo\itshape\rightmark}}
  {}
  {{\let\decide\@firstoftwo\itshape\rightmark}\quad--\quad\thepage}
\makeheadrule{chapter}{\textwidth}{\normalrulethickness}
\makeatother

\providecommand{\decide}[2]{} % in case something goes wrong

\begin{document}

\pagestyle{myheadings}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\protect\decide{\thesection}{#1}}}

\markright{\protect\decide{1.1}{Section one (Without this macro, there'd be no text here!)}}

\chapter{The only chapter}

命令\sectionmark发出\protect\decide{\thesection}{Title of the section}(传递给的参数\sectionmark始终是标题)。然后我们在排版时决定需要什么参数,当需要章节编号时将\decide其设置为,当需要标题时将其设置为。\@firstoftwo\@secondoftwo

注意:在任何情况下,我都不会在章节的第一页上放置页眉,更不用说在页眉下方设置规则了:页眉所包含的信息很容易从页面本身获取。

“几乎”指的是某些情况下,版权声明会出现在每一页上:意大利的一些出版商采用这种策略来避免未经授权的复印他们的书籍,他们希望版权符号后面跟着 ISBN 号。不过,这个数字是小字体,不太显眼(尽管不好看)。

相关内容