Difference between revisions of "Layers"

From ConTeXt wiki
(Links)
(made some corrections and added to Layers and Graphics categories)
Line 7: Line 7:
 
=My first Layer=
 
=My first Layer=
  
Define a layer that takes the whole page, but starts with an offset
+
Define a layer that takes the whole page
 
<texcode>
 
<texcode>
 
\definelayer [mybg] % name of the layer
 
\definelayer [mybg] % name of the layer
[x=-3mm, y=-3mm, % bleed over the page
+
[x=0mm, y=0mm, % from upper left corner of paper
width=\paperwidth, height=\paperheight]
+
width=\paperwidth, height=\paperheight] % let the layer cover the full paper
 
</texcode>
 
</texcode>
  
Now you can put something on that layer:
+
Now you can put something in that layer:
 
<texcode>
 
<texcode>
 
\setlayer [mybg] % name of the layer
 
\setlayer [mybg] % name of the layer
[x=2cm, y=5cm] % placement (from upper left corner of the layer)
+
[hoffset=1cm, voffset=1cm] % placement (from upper left corner of the layer)
{\framed[frame=on, width=3cm, height=2cm]{LAYER}}
+
{\framed[frame=on, width=3cm, height=2cm]{LAYER}} % the actual contents of the layer
 
</texcode>
 
</texcode>
  
 
Activate the layer as a background:
 
Activate the layer as a background:
 
<texcode>
 
<texcode>
\setupbackgrounds [page] [background=mybg]
+
\setupbackgrounds[page][background=mybg]
 
</texcode>
 
</texcode>
 
+
This command makes the layer appear only once after the background is activated. If you want to repeat the layer on each page, use the option <code>repeat=yes</code> in the <cmd>definelayer</cmd> command.
You could also typeset the layer once using <cmd>placelayer</cmd> or <cmd>flushlayer</cmd>, but then the location depends from the upper left of the text area! (Bug?)
 
 
 
* switch off backgrounds: <code>\setupbackgrounds[page][background=]</code>
 
* add a background: <code>\setupbackgrounds[page][background={\currentvalue, mylayer}]</code>
 
  
 
==Placement==
 
==Placement==
Line 56: Line 52:
 
* Source: [[source:page-lyr.tex|page-lyr]]
 
* Source: [[source:page-lyr.tex|page-lyr]]
 
* Example of [[alternating backgrounds and repeating layers]]
 
* Example of [[alternating backgrounds and repeating layers]]
 +
 
{{todo|We need a lot of documentation and samples for this complicated subject.}}
 
{{todo|We need a lot of documentation and samples for this complicated subject.}}
 +
 +
[[Category:Graphics]] [[Category:Layers]]

Revision as of 15:03, 9 March 2007

< Layout | Columns | Overlays | Logos >

Layers are ConTeXt's mechanism for absolute positioning of elements and other advanced techniques like switching elements on and off.

There's still no manual about them.

My first Layer

Define a layer that takes the whole page

\definelayer	[mybg]	% name of the layer
		[x=0mm, y=0mm,	% from upper left corner of paper
		width=\paperwidth, height=\paperheight] % let the layer cover the full paper

Now you can put something in that layer:

\setlayer	[mybg]	% name of the layer
		[hoffset=1cm, voffset=1cm]  % placement (from upper left corner of the layer)
		{\framed[frame=on, width=3cm, height=2cm]{LAYER}}  % the actual contents of the layer

Activate the layer as a background:

\setupbackgrounds[page][background=mybg]

This command makes the layer appear only once after the background is activated. If you want to repeat the layer on each page, use the option repeat=yes in the \definelayer command.

Placement

There are several possibilities for defining the placement of layer content:

  • x, y : offset from upper left corner of paper
  • hoffset, voffset : offset from upper left corner of layer
  • corner : reference point, something like {left, top}
  • location : alignment of the element relative to the corner, something like {right, bottom}
  • preset : a named location, see below

There are some "presets" for paper egde placement:

% These four are defined by ConTeXt!
\definelayerpreset	[lefttop]	[corner={left,top}, location={right,bottom}]
\definelayerpreset	[righttop]	[corner={right,top}, location={left,bottom}]
\definelayerpreset	[leftbottom]	[corner={left,bottom}, location={right,top}]
\definelayerpreset	[rightbottom]	[corner={right,bottom}, location={left,top}]

Similarly you can define your own presets.

Links


TODO: We need a lot of documentation and samples for this complicated subject. (See: To-Do List)