设置 ConTeXt 中章节第一页的布局

设置 ConTeXt 中章节第一页的布局

在设计一些文档的时候,希望能设置一个全局的布局,另外给所有章节的第一页设置一个布局,我定义了两个布局如下:

\setuppagenumbering
[alternative=doublesided,
 location=]

% global layout for the whole document
\setuplayout
[backspace=2.5cm,
 width=16.5cm,
 topspace=2cm,
 height=25.2cm,
 header=\lineheight,
 headerdistance=\lineheight,
 footer=0cm]

% layout for the first page of Chapters
\definelayout
[firstpage]
[height=26.2cm,
 footerdistance=\lineheight,
 footer=\lineheight]

\starttext
\chapter{First Chapter}
I am in the first page.
\page
I am in the second page.
\stoptext

现在的问题是,我如何将此firstpage布局应用于该章节的第一页First Chapter并切换回global layout该章节第一页之后?

答案1

您可以使用\setupheadbefore键在新章节开始时更改布局。页面发出后,设置将重置为默认值。

\setuppapersize [A6]  %% only for screenshot

\definelayout
  [firstpage]
  [height=8cm]

\setuphead
  [chapter]
  [before=\ChapterPageHook]

\starttexdefinition ChapterPageHook
  \appendtoks
    \setuplayout[reset]
  \to\everyshipout
  \setuplayout[firstpage]
\stoptexdefinition

\showframe
\starttext
  \startchapter [title=First Chapter]
  I am in the first page. \page
  I am in the second page.
  \stopchapter

  \startchapter [title=Second Chapter]
  I am in the first page. \page
  I am in the second page.
  \stopchapter
\stoptext

screenshot

答案2

此变体修复了@tstenner 指出的文本区域的问题:

\setuplayout
[backspace=2.5cm,
 width=16.5cm,
 topspace=2cm,
 height=25.2cm,
 header=\lineheight,
 headerdistance=\lineheight,
 footer=0cm]

\definelayout
  [firstpage]
  [height=8cm]

\setuphead
  [chapter]
  [before=\ChapterPageHook]

\starttexdefinition ChapterPageHook
  \setuplayout[firstpage]
    \scratchcounter\pagenumber
    \def\nextPage{\number\numexpr\scratchcounter + 1}
    \definelayout[\nextPage][reset]
\stoptexdefinition

\showframe
\starttext
  \startchapter [title=First Chapter]
  I am in the first page. \input knuth \page
  I am in the second page.\dorecurse{3}{\input knuth}
  \stopchapter

  \startchapter [title=Second Chapter]
  I am in the first page. \input knuth \page
  I am in the second page.\dorecurse{3}{\input knuth}
  \stopchapter
\stoptext

如果这只影响章节的第二页,请尝试此方法。出于某种原因,它使布局更改保持不变。

\def\nnextPage{\number\numexpr\scratchcounter + 2}
\definelayout[\nnextPage][reset]

相关内容