下面的 MWE 在所有(正面和反面)页眉的中间部分打印相同的文本(即章节标题)。是否可以在页眉的中间部分打印不同的文本(例如,反面页面上的作者姓名和正面页面上的章节标题)?
\mainlanguage[en]
\language[en]
\setuplayout[grid=yes]
\setupindenting[yes,small]
% Text in the middle section of ALL headers (both recto and verso pages).
\setupheadertexts[chapter]
% Page number on the header. Recto pages: on the right; verso pages: on the left.
\setupheadertexts[][pagenumber][pagenumber][]
% Set up headers.
\setupheader[state=normal, style=sc]
% Place page number in the middle of the footer on chapter title pages.
\definetext[chapterpagenumber][footer][pagenumber]
% Chapter
\setuphead
[chapter]
[align=middle,header=empty,footer=chapterpagenumber,number=no,page=right,textstyle=WORD]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\starttext
\chapter{First Chapter}
\input knuth
\input knuth
\input knuth
\input knuth
\input knuth
\input knuth
\input knuth
\input knuth
\input knuth
\input knuth
\input knuth
\input knuth
\stoptext
答案1
ConTeXt 标头布局并不是非常灵活,但你可以通过一些额外的工作来实现所需的布局。有三个要素:
您想区分正面和反面页面,因此您可能希望边距也能自动适应这一点。为此,您明确告诉 ConTeXt 您想要双面排版。此外,我们关闭了页码,因为我们想手动放置它。
\setuppagenumbering[alternative=doublesided,location=]
使用文档元数据。而不是
\starttext
使用\startdocument
,它的作用与 完全相同,\starttext
但允许您设置文档变量。如果您启用超链接(\setupinteraction[state=start]
),此元数据也将自动填充到 PDF 属性中。\startdocument [metadata:author={A. U. Thor}, metadata:title={A short story}]
现在我们手动设置页眉(某种程度上)。您已经知道了
pagenumber
,所以我们从那里开始。在背面页面的左侧页眉中我们填写{\hfill\getmarking[chapter]\hfill}
,在正面页面中使用{\hfill\documentvariable{metadata:author}\hfill}
。这\hfill
将覆盖左右对齐并将页眉居中。\setupheadertexts [{\hfill\getmarking[chapter]\hfill}][pagenumber] [pagenumber][{\hfill\documentvariable{metadata:author}\hfill}]
完整示例:
\mainlanguage[en]
\language[en]
\setuplayout[grid=yes]
\setupindenting[yes,small]
% Set up headers.
\setuppagenumbering[alternative=doublesided,location=]
\setupheadertexts
[{\hfill\getmarking[chapter]\hfill}][pagenumber]
[pagenumber][{\hfill\documentvariable{metadata:author}\hfill}]
\setupheader[state=normal, style=sc]
% Place page number in the middle of the footer on chapter title pages.
\definetext[chapterpagenumber][footer][pagenumber]
% Chapter
\setuphead
[chapter]
[align=middle,header=empty,footer=chapterpagenumber,number=no,page=right,textstyle=WORD]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\startdocument
[metadata:author={A. U. Thor},
metadata:title={A short story}]
\chapter{First Chapter}
\input knuth
\input knuth
\input knuth
\input knuth
\input knuth
\input knuth
\input knuth
\input knuth
\input knuth
\input knuth
\input knuth
\input knuth
\stopdocument