8

When designing some documents, I hope I can set a global layout and another layout for the first page of all chapters. I have defined two layouts as follows:

\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

Now the question is that how I can apply this firstpage layout to the first page of the chapter First Chapter and switch back to the global layout after the first page of this chapter?

2 Answers 2

5

You can use \setuphead and the before key to change the layout when a new chapter starts. The setting is reset to the default value when a page is shipped out.

\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

5
  • \adpatlayout is simpler than the \appendtoks jugglary.
    – Aditya
    Aug 4, 2013 at 22:07
  • @Aditya \adaptlayout only adjusts the text height. It does not allow to select a different layout, if I'm not mistaken. I tried to simplify the OPs code. Varying the text height probably wasn't the best choice.
    – Marco
    Aug 4, 2013 at 22:21
  • You are right. \adaptlayout only checks for height and lines keys. However, one must use \setuplayout[reset] with care. In particular if the main layout is activated using \definelayout[name][...] followed by \setuplayout[name], then \setuplayout[reset] will reset to default layout rather than name layout.
    – Aditya
    Aug 5, 2013 at 0:30
  • 1
    With headerdistance=1cm in the firstpagelayout, the textheight is reduced in all following pages. Is there any way to circumvent this?
    – tstenner
    May 3, 2019 at 13:07
  • Even with this MWE, try replacing the text ("I am…") with \the\textheight – the frame is larger, but the area for text is shrunk for all pages
    – tstenner
    May 6, 2019 at 12:54
1

This variant fixes the issue with the area of text pointed out by @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

If that that only affects the second page of the chapter, try this. For some reason it makes the layout change stick.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .