Difference between revisions of "Page Layout"

From Wiki
Jump to navigation Jump to search
(→‎Multiple layouts: Note about different layouts for pages specified by their page number)
Line 306: Line 306:
 
</texcode>
 
</texcode>
  
''This text is based on at [http://archive.contextgarden.net/message/20080926.111520.9db86904.en.html a thread on the mailing list], answers and examples are given there by Hans and Wolfgang.''
+
''This text is based on [http://archive.contextgarden.net/message/20080926.111520.9db86904.en.html a thread on the mailing list], answers and examples are given there by Hans and Wolfgang.''
  
 
Defining layouts with a number as their name allows to specify the layout of the page with that specific number. For example, to use a different layout for the first page, you can use this code:
 
Defining layouts with a number as their name allows to specify the layout of the page with that specific number. For example, to use a different layout for the first page, you can use this code:
  
 
<texcode>
 
<texcode>
\setuplayout[key=value,key=value,...] %global layout
+
\setuplayout[key=value,key=value,...] % global layout
\definelayout[1][key=value,key=value,...] %layout of the first page
+
\definelayout[1][key=value,key=value,...] % layout of the first page
 
\definelayout[2][reset] % revert to the global layout starting from the second page
 
\definelayout[2][reset] % revert to the global layout starting from the second page
 
</texcode>
 
</texcode>
  
 
Do not forget to reset the layout on the second page. Note that keys that are not set in the layout of the first page will be conveniently inherited from the global layout.
 
Do not forget to reset the layout on the second page. Note that keys that are not set in the layout of the first page will be conveniently inherited from the global layout.
 +
 +
A typical example of the above is the following:
 +
<texcode>
 +
\setuplayout[% default layout for all the pages
 +
backspace=1cm,
 +
width=middle]
 +
 +
\definelayout[1][% set this layout on the first page
 +
backspace=6cm]
 +
 +
\definelayout[2][reset] % reset to the default layout starting from the second page
 +
 +
\definelayout[5][backspace=6cm] % use this layout starting from  page 5
 +
 +
\definelayout[9][reset] % reset to the default layout starting from  page 9
 +
 +
\starttext
 +
\showframe
 +
\dorecurse{20}{\input dawkins \blank[big] \input knuth \page}
 +
\stoptext
 +
</texcode>
  
 
== Layout components ==
 
== Layout components ==

Revision as of 20:24, 1 January 2011

< Visuals | Layers | Columns | Visual Debugging >

There is now a manual chapter on page design!

Location of Areas

You can use these design areas in your page:

leftedge leftmargin width rightmargin rightedge
top . . ↑ topspace ↓ . .
header . . HEADER
↑ headerheight ↓
. .
textheight ←leftedgewidth→ MARGINALS
←leftmarginwidth→
TEXT
←textwidth→
×
↑ textheight ↓
MARGINALS
←rightmarginwidth→
←rightedgewidth→
footer . . FOOTER
↑ footerheight ↓
. .
bottom . . ↑ bottomspace ↓ . .


The names in the column and row headers are the keywords for \setuplayout, the words inside of the table are given to clarify ConTeXT terminology. There are also keywords suffixed by "distance" to set the distance between each of the areas, e.g. leftedgedistance, leftmargindistance (from the named area to the inner).

height is normally used instead of textheight, it is the sum of footer + footerdistance + textheight + headerdistance + header

The size of the margins does not affect the size of the text area. Control the size of the text area with backspace, topspace, height and width.

Table of Parameters

ParameterVariableRemarks
paperheight \paperheight height of paper page
paperwidth \paperwidth width of paper page
printpaperheight \printpaperheight differs from paperheight when using Imposition (arranging)
printpaperwidth \printpaperwidth differs from paperwidth when using Imposition (arranging)
topspace \topspace above header: from top rim of paper to to top rim of header
backspace \backspace from left rim of paper to left rim of main text area
height \makeupheight sum of heights of text area, header and footer (plus distances)
width \makeupwidth width of the main text area. \makeupwidth is normally same as \textwidth, but it can be different, for example in columns
top \topheight height of the top area
topdistance \topdistance between top and header
header \headerheight height of header area
headerdistance \headerdistance between header and text
textheight \textheight height of text area
footerdistance \footerdistance between text and footer
footer \footerheight height of footer area
bottomdistance \bottomdistance between footer and bottom
bottom \bottomheight space below footer (but isn't calculated automatically)
bottomspace \bottomspace space from bottom footer to bottom rim of paper
cutspace \cutspace from right rim of paper to right rim of main text area
leftedge \leftedgewidth from left rim of paper to left rim of left margin
leftedgedistance \leftedgedistance between leftegde and left margin
leftmargin \leftmarginwidth width of left margin (marginals space)
leftmargindistance \leftmargindistance between left margin and text
textwidth \textwidth width of text area. when columns are used, the value of \textwidth can differ from \makeupwidth
rightmargindistance \rightmargindistance between text area and right margin
rightmargin \rightmarginwidth width of right margin (marginals area)
rightedgedistance \rightedgedistance between right margin and right edge
rightedge \rightedgewidth from right margin to right rim of paper

Note:

  • width=middle

    if cutspace == 0pt then
       cutspace = backspace
    end
    makeupwidth =  paperwidth- backspace -cutspace

  • width=fit

      if cutspace == 0pt then
         cutspace = backspace
      end
      makeupwidth = paperwidth-cutspace
      scratchdimen = backspace - leftedgewidth-leftedgedistance-leftmarginwidth-leftmargindistance
      if scratchdimen< 0pt then
         scratchdimen = 0pt
      end
      makeupwidth = makeupwidth - rightmargindistance-rightmarginwidth- rightedgedistance-rightedgewidth- scratchdimen

  • otherwise:

      makeupwidth=width
      if cutspace == 0pt then
         cutspace = paperwidth-makeupwidth-backspace
      else
           % A kind of inconsistent specification, but used
           % in for instance s-pre-19.tex; the cutspace is
           % used only for determining some kind of right
           % margin; don't use this in doublesided mode
      pass 
      end

(from page-lay.mkiv, 2009-11-17 - 23:59).

Setup / Paper Size

You define always a right page; if you use a double page layout 'right' and 'left' values are mirrored on a left page.

\setuppapersize[A4][A4] % this is default and may be omitted
\setuplayout[backspace=20mm,
	width=160mm,
	topspace=20mm, top=0mm,
	header=0mm, footer=0mm,
	height=250mm]

ConTeXt users in the United States might use

\setuppapersize[letter][letter]

for standard US Letter-sized paper (8.5" × 11.0")

If you need a special paper size, have a look at our list of paper sizes (ConTeXt's, standardized and traditional), and use \definepapersize if it's not already defined.

You can make all the geometry information visible with \showlayout and the related commands.

See \setuplayout and \setuppapersize in the manual.

How to setup your layout

Define the placement and size of your type area by first defining backspace, topspace, width and height. The height includes header and footer.

The width of the margins has no influence on the location of the type area!

Details are in the page design chapter of the new reference manual.

Keep

If you have a certain run of text that you want to keep together, you can test for the number of lines available on the current page with \testpage[n] where n is the number of lines required. If there are not n lines available, a page break will be inserted at the location of the testpage command.


Multiple layouts

If you need to use different layouts in some parts of the document, you can set up a global layout for the overall and then define additional named layouts for the deviating parts. These settings go into the setup area of your document.

\setuplayout[key=value,key=value,...] %global layout
\definelayout[wide][key=value,key=value,...] %different layout called 'wide'
\definelayout[short][key=value,key=value,...]%different layout called 'short'

That takes care of the global layout. When you want to switch to a different layout, you just call it up in the appropriate place in the document:

\setuplayout[wide] % switches to layout called 'wide'

Note. Use reset to revert back to the global layout:

\setuplayout[reset] % reverts to the global layout

This text is based on a thread on the mailing list, answers and examples are given there by Hans and Wolfgang.

Defining layouts with a number as their name allows to specify the layout of the page with that specific number. For example, to use a different layout for the first page, you can use this code:

\setuplayout[key=value,key=value,...] % global layout
\definelayout[1][key=value,key=value,...] % layout of the first page
\definelayout[2][reset] % revert to the global layout starting from the second page

Do not forget to reset the layout on the second page. Note that keys that are not set in the layout of the first page will be conveniently inherited from the global layout.

A typical example of the above is the following:

\setuplayout[% default layout for all the pages
	backspace=1cm,
	width=middle]

\definelayout[1][% set this layout on the first page
	backspace=6cm]

\definelayout[2][reset] % reset to the default layout starting from the second page

\definelayout[5][backspace=6cm] % use this layout starting from  page 5

\definelayout[9][reset] % reset to the default layout starting from  page 9

\starttext
\showframe
\dorecurse{20}{\input dawkins \blank[big] \input knuth \page}
\stoptext

Layout components

A hidden nice feature is

\showlayoutcomponents

By adding the above command at the beginning of your file you obtain a PDF file in which different components of the layout (such as layers) can be made visible or invisible in Acrobat Reader (or maybe a few other PDF viewers).

Hints

By using Layers, you can also place elements at specific places, as done in the BusinessCard example.

At Paul Tremblay's XML ConTeXt site, there's a lot about layout from a XML/FO perspective with some descriptive pictures.


TODO: Unfortunately it's not that easy to define a layout. We need more documentation about which parameters define which length, what influences what else etc. (See: To-Do List)