Document layout and layers/Tutorials

From Wiki
Jump to navigation Jump to search

Defining the paper size

Set the page size and its orientation with \setuppapersize.

  • \setuppapersize[A8]
    \starttext
    Hello world !
    \stoptext
    
  • \setuppapersize[A8,landscape]
    \starttext
    Hello world !
    \stoptext
    

Paper setup page provides further important features and options.

Typesetting areas

A ConTeXt page is divided into 5 columns and 5 rows, giving 25 areas. as illustrated by the graphic below, which also shows the associated dimensions.

Diagram of \setuplayout[] dimensions

  • The row and column names are written along the edges of the page.
  • The arrows correspond to layout dimensions;
  • the more important a dimension is (i.e. the more of the layout is pushed around when you change it), the thicker its arrow and the larger its name.
  • From left to right, one encounters leftedge, leftmargin, text, rightmargin, and rightedge.
  • From top to bottom, the areas are called: top, header, text, footer, bottom.

E.g.

  • leftmargin is the margin area to the left of the main text area,
  • {leftmargin,bottom} is below it, at the same height as the bottom area,
  • in between the two lies the area {leftmargin,footer}.

Defining the layout

Positioning the areas is by setting the following dimensions using \setuplayout[backspace=5cm,...]. The dimensions are mentioned in order of how ‘primitive’ they are: e.g. altering the topspace pushes around all other vertical dimensions, but altering the header affects only the headerdistance and the textheight.\

Use \showframe in the setup area to visualize the typesetting areas.

When you define a page layout, it's always a right page that you're defining; if you use a double page layout, 'right' and 'left' values are mirrored on a left page. Doublesided typesetting is activated with \setuppagenumbering[alternative=doublesided].

Now let's proceed in order:

  1. Set the backspace and width, and the topspace and height. The width is the width of the main typesetting area; the backspace is its distance from the left edge of the page. The height is the distance from the top of the header to the bottom of the footer; the topspace is the distance from the top edge of the page to the top of the header.
  2. Set the header and headerdistance, and the footer and footerdistance. The header is the vertical size of the header area; the headerdistance is the distance from the header area to the text area. The footer and footerdistance work likewise.
  3. Once the header(distance) and footer(distance) are subtracted from the height, what remains is the textheight: the height of the main typesetting area. Although it would be very useful, you cannot set this dimension directly.
  4. If you want to typeset anything above the header, define topdistance (the distance from the top of the header to the bottom of the topmost typesetting area) and top (the height of the topmost typesetting area). For typesetting below the footer, define bottomdistance and bottom.
  5. As for the horizontal dimensions apart from the width: starting at the left edge of the main text area, and moving away from the center, one first sets the leftmargindistance; then one sets the width leftmargin of the margin typesetting area; then one sets the leftedgedistance; and then there is the leftedge typesetting area. On the right: rightmargindistance, rightmargin, rightedgedistance, rightedge.

TODO: illustrate the middle and fit options for width and height, Command/setuplayout#Description (See: To-Do List)


Examples layout

  • \setuppapersize[A8]
    \showframe
    \setuplayout
      [backspace=6mm,
       width=40mm,
       topspace=2mm,
       header=4mm,
       footer=4mm,
       headerdistance=1mm,
       footerdistance=1mm,
       margin=4mm,
       margindistance=1mm,
       height=70mm]
    \starttext
    Hello world !
    \stoptext
    

Adding headers and footers

Adding headers and footers is done with \setupheadertexts and \setupfootertexts. Usually you use these command twice:

  • a first time with one argument [argument] in order to define what will appear in the middle
  • a second time with two [arg1][arg2] (or four if you work with a double-sided document, see below)
  • \setuppapersize[A8]
    \setuppagenumbering[alternative=doublesided]
    \setupheadertexts[B]
    \setupheadertexts[A][C]
    \starttext
    Hello world !
    \stoptext
    

But usually you need useful information there. There are predefined keywords for popular values, like

  • [chapter]
  • [section]
  • [pagenumber]
  • [date]

By default you have the page number in the middle of the header, like if you would have asked for \setupheadertexts[pagenumber]. If you don't want the pagenumber there, you have to define \setupheadertexts [] in order to let this area empty.

Let's try amother example:

  • \setuppapersize[A8]
    \setupheadertexts []               % To make it empty
    \setupheadertexts [date] [section]
    \setupfootertexts [pagenumber]
    
    \starttext
    \startsection[title=Hello]
     world !
    \stopsection
    \stoptext
    

You can customize the content, but then pay attention to give a group as argument, i.e. to provide your customization between {}

  • \setuppapersize[A8]
    \setupheadertexts []               % To make it empty
    \setupheadertexts [] [{\tfx\sc\getmarking[section]}]
    \setupfootertexts [{\star}]
    \setupfootertexts [{\color[darkred]{page \pagenumber}}] []
    
    \starttext
    \startsection[title=Hello]
     world !
    \stopsection
    \stoptext
    

Double-sided

The principle is the same, but you have

  • \definepapersize[sheet][width=156mm,height=74mm]
    \setuppapersize[A8][sheet]
    \setuppaper[nx=3,ny=1]
    \setuparranging[XY]
    \showframe[edge]
    
    \setupheadertexts [x]
    \setupheadertexts [C] [D] [B] [A]
    \setupfootertexts [y] 
    \setupfootertexts [G] [H] [F] [E]
    
    \starttext
    \startsection[title=Hello]
     world !
    \page
    with 
    \page
    \ConTeXt
    \stopsection
    \stoptext