密切相关:
-为章节标题和内容页创建单独的页脚和页眉?
1.用例-将布局与内容分离:
内容作者将通过网络门户提供 TeX 内容,其中可能包括\chapter{Chapter Title}
脚注、数学、图像和其他 TeX 语法。
然而,通常情况下,这些作者可能会错误地指定默认值chapter title page
和样式,或者chapter content page
受到损坏通过其他进口(、、\input
等)\include
\usepackage
澄清:AChapter Title Page
是章节的第一页。Chapter Content Pages
是章节的其余内容页。这与目录无关,但不应影响目录。
2.问题:
使用回忆录、书籍或其他文档类别,是否可以执行与相关问题相同的操作\xpatchcmd
?
是否可以仅定义和应用自定义类一次来影响整个文档的所有Chapter Title Pages
内容,而无需像类似问题中所见的那样重复所有代码?Chapter Content Pages
目标:
- 能够分别为章节标题页和章节内容页定义页眉和页脚(当前答案无法做到这一点)。
- 最终为书中的每个部分提供单独的自定义样式(而不必担心默认样式被破坏)。
- 减少代码重复。
- 可以覆盖导入文档中不受欢迎的定制。
- 将
\xpatchcmd
任何其他修补命令列入黑名单并禁止使用。
3.代码示例:
\documentclass{memoir}
\usepackage{lipsum}
\makepagestyle{chapter}
\makeheadrule{chapter}{\textwidth}{\normalrulethickness}
\makefootrule{chapter}{\textwidth}{\normalrulethickness}{\footruleskip}
\makeoddhead {chapter}{left header}{odd header}{right header}
\makeoddfoot {chapter}{left footer}{odd footer}{right footer}
% ***** Added in Even Page Headers and Footers to show on Chapter Content Pages
\makeevenhead {chapter}{left header}{even header}{right header}
\makeevenfoot {chapter}{left footer}{even footer}{right footer}
\makepagestyle{alternate}
\makeheadrule{alternate}{\textwidth}{\normalrulethickness}
\makefootrule{alternate}{\textwidth}{\normalrulethickness}{\footruleskip}
\makeoddhead {alternate}{left header}{alternate odd header}{right header}
\makeoddfoot {alternate}{left footer}{alternate odd footer}{right footer}
\makeevenhead {alternate}{left header}{alternate even header}{right header}
\makeevenfoot {alternate}{left footer}{alternate even footer}{right footer}
\begin{document}
% ***** What Memoir Code could go here, to override all
% ***** chapter title and content pagestyles?
% ***** How to specify all chapter Title and Content Pages
% ***** ... without having to provide an actual chapter.
% ***** ... \xpatch can do this, but does Memoir have a way?
\chapter{Non-Styled Chapter}
\chapterprecis{Ideally the only code would be the \\ include command. Authors will only have TeX code specific to their own content - with no knowledge of current styles, etc. There would be no "\\ pagestyle" commands in these \\ include -ed files. Here, chapter content pages have no custom headers and footers. }
% \include("./Content/MyContent.text")
\sloppy\lipsum
\chapter{Test Chapter With required \\ pagestyle command}
\chapterprecis{Required to use inner Styling to get Headers and Footers.}
% **** Chapter Content Pages Need this \pagestyle command?
\pagestyle{chapter}
\sloppy\lipsum
% ***** Every \chapter tag would reqire \chapterstyle, etc.
% ***** Chapter Content will actually be pulled in via \include.
\chapterstyle{bianchi}
\chapter{Testing Bianchi Chapter Style}
\chapterprecis{Built in Chapter Styles have no impact on headers and footers.%
Have to resort to including \\ pagestyle in order to override possible%
corruption of default \\ pagestyle\{chapter\} }
\pagestyle{alternate}
\sloppy\lipsum
% ***** Bianchi Chapter Test 2, Without Style Tags
\chapter{Non-Styled Chapter}
\chapterprecis{Chapter Without Any Style Commands. Inherits globally altered changes. This is what I am hoping to avoid.}
\sloppy\lipsum
\end{document}
答案1
\xpatchcmd
(从xpatch
)与其对应物\patchcmd
(来自etoolbox
):
\xpatchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\xpatchcmd
搜索<search>
in<cmd>
并将其替换为<replace>
。如果此搜索和替换成功,则执行<success>
,否则执行<failure>
。在您的代码示例中(删除注释后),
\xpatchcmd{\chapter}{\thispagestyle{chapter}}{}{}{}
搜索\thispagestyle{chapter}
内部\chapter
并将其替换为空。为简洁起见,<success>
和<failure>
分支也留空。实际上,上述命令会\thispagestyle{chapter}
从中删除\chapter
。
其次,你混淆\chapterstyle
了\pagestyle
。它们是不同的。章节样式(使用 定义\makechapterstyle
)与 的调用一起使用\chapterstyle
,并定义设置章节标题的方式,而不是章节页眉/页脚。后者称为页样式是通过(仅适用于当前页面)或(适用于从当前页面开始的页面)创建的\makepagestyle
,并通过其使用/设置。\thispagestyle
\pagestyle
以下是veelo
章节风格,例如:
% ...
\setcounter{chapter}{3}% Just for this example
\chapterstyle{veelo}
\chapter{Demonstration of the veelo \\ chapter style}
\sloppy\lipsum
%...
标题 - Chapter 4
- 和标题 - Demonstration of the veelo \\ chapter style
- 的设置方式已经改变,但页风格依旧chapter
。
以下是应用ChapterPage
页样式到第一页\chapter
下madsen
章节风格:
\documentclass{memoir}
\usepackage{lipsum,graphicx}
\makepagestyle{ChapterPage}
\makeheadrule{ChapterPage}{\textwidth}{\normalrulethickness}
\makefootrule{ChapterPage}{\textwidth}{\normalrulethickness}{\footruleskip}
\makeoddhead {ChapterPage}{left header}{centre header}{right header}
\makeoddfoot {ChapterPage}{left footer}{centre header}{right header}
\begin{document}
\tableofcontents
\clearpage
\copypagestyle{chapter}{ChapterPage}
\setcounter{chapter}{3}% Just for this example
\chapterstyle{madsen}
\chapter{Demonstration of the madsen \\ chapter style}
\sloppy\lipsum
\end{document}
\chapter
默认情况下,给出第一页\thispagestyle{chapter}
(参见memoir
文档, 部分7.2 页面样式)并且chapter
页面样式是副本 - 实际上是别名- plain
(参见章节7.3 制作页眉和页脚)。
首先,您必须完整地创建chapter
页面样式,可以采用全新的样式(通过\makepagestyle{chapter}
),也可以复制其他样式(如\copypagestyle{chapter}
)。
然后您可以更改样式以满足您的需要:
\makepagestyle{chapter}% Officially create the chapter page style
\makeheadrule{chapter}{<width>}{<thickness>}% Header rule specification
\makefootrule{chapter}{<width>}{<thickness>}{<skip>}% Footer rule specification
\makeevenhead{chapter}{<left>}{<centre>}{<right>}% Even header
\makeoddhead {chapter}{<left>}{<centre>}{<right>}% Odd header
\makeevenfoot{chapter}{<left>}{<centre>}{<right>}% Even footer
\makeoddfoot {chapter}{<left>}{<centre>}{<right>}% Odd footer
这是一个完整的最小示例,重点介绍了该过程:
\documentclass{memoir}
\usepackage{lipsum}
% This creates (and overrides) the chapter page style - set on the
% first page of a \chapter
\makepagestyle{chapter}
\makeheadrule{chapter}{\textwidth}{\normalrulethickness}
\makefootrule{chapter}{\textwidth}{\normalrulethickness}{\footruleskip}
\makeoddhead {chapter}{left header}{chapter odd header}{right header}
\makeoddfoot {chapter}{left footer}{chapter odd footer}{right footer}
\makeevenhead{chapter}{left header}{chapter even header}{right header}
\makeevenfoot{chapter}{left footer}{chapter even footer}{right footer}
% This is everything else - set on "chapter content" pages
\makepagestyle{alternate}
\makeheadrule{alternate}{\textwidth}{\normalrulethickness}
\makefootrule{alternate}{\textwidth}{\normalrulethickness}{\footruleskip}
\makeoddhead {alternate}{left header}{alternate odd header}{right header}
\makeoddfoot {alternate}{left footer}{alternate odd footer}{right footer}
\makeevenhead{alternate}{left header}{alternate even header}{right header}
\makeevenfoot{alternate}{left footer}{alternate even footer}{right footer}
\pagestyle{alternate}
\begin{document}
\sloppy% Just for this example
\chapter{Non-Styled Chapter}
\chapterprecis{Ideally the only code would be the \texttt{\string\include} command.
Authors will only have TeX code specific to their own content - with no knowledge of current styles,
\textit{etc.} There would be no ``\texttt{\string\pagestyle}'' commands in these \texttt{\string\include}-ed files.
Here, chapter content pages have no custom headers and footers.}
\lipsum
\chapter{Test Chapter With required \texttt{\string\pagestyle} command}
\chapterprecis{Required to use inner Styling to get Headers and Footers.}
\lipsum
\chapterstyle{bianchi}
\chapter{Testing Bianchi Chapter Style}
\chapterprecis{Built in Chapter Styles have no impact on headers and footers.%
Have to resort to including \texttt{\string\pagestyle} in order to override possible%
corruption of default \texttt{\string\pagestyle\string{chapter\string}}}
\lipsum
\chapter{Non-Styled Chapter}
\chapterprecis{Chapter Without Any Style Commands. Inherits globally altered changes.
This is what I am hoping to avoid.}
\lipsum
\end{document}