1

I could put the following Tikz code on a single page:

\tikz[remember picture,overlay] 
\shade[top color=green!30, bottom color=blue!30] 
(current page.north west) rectangle (current page.south east);

However, it fails if I try to use it as a background for all pages.

I was also unsure whether to use overlays or layers -- tried both (see below)

\usemodule[t-tikz]
\usetikzlibrary[shapes.geometric,arrows,arrows.meta,positioning,mindmap,shadows,trees,calc]

\defineoverlay[sombra][
\tikz[remember picture,overlay] 
\shade[top color=green!30, bottom color=blue!30] 
(current page.north west) rectangle (current page.south east);
]

%\setupbackgrounds[page][background=sombra]


\setlayer[mybg] % name of the layer
%[hoffset=1cm, voffset=1cm]  % placement (from upper left corner of the layer)
{\tikz[remember picture,overlay] 
\shade[top color=green!30, bottom color=blue!30] 
(current page.north west) rectangle (current page.south east);
}  % the actual contents of the layer


\setupbackgrounds[page][background=mybg,
state=repeat % repeat each page
]

\starttext

asdf asdf

\stoptext

Edit

I was able to get it working with this -- though I've got to fix this white part with some offset I couldn't figure out so far.

\setuppagenumbering
 [alternative=doublesided]

\setupcolors
 [state=start]

\definelayer
 [fundo]
 [repeat=yes,
  width=\paperwidth,
  height=\paperheight]

\usemodule[t-tikz]
\usetikzlibrary[shapes.geometric,arrows,arrows.meta,positioning,mindmap,shadows,trees,calc]

\setlayer
[fundo]
[preset=middle]
{\tikz[remember picture,overlay] 
\shade[top color=green!30, bottom color=blue!30](current page.north west) rectangle (current page.south east);}


\setupbackgrounds
[page]
[background=fundo]


\starttext
asdf
\page
asdf
\stoptext
4
  • You should report it as a bug to Henri Menke (it works with LuaTeX, but not LuaMetaTeX). If you consider another alternative, you could do the same using MetaPost.
    – user226564
    Jan 26, 2021 at 11:59
  • @JairoA.delRio, Thanks. I guess it could be fairly simple with Metapost, but adapting the examples from the manual was beyond my capabilities at the moment. Besides, should it work layer or overlay?
    – user9424
    Jan 26, 2021 at 12:03
  • Oh, you only put the TikZ code in the page you need it (no overlays nor layers), the same as LaTeX. If it doesn't compile for you, use context --luatex <filename>. If it's helpful, I'll post a solution using MetaPost
    – user226564
    Jan 26, 2021 at 12:06
  • Yes, that was another possibility. I guess it worked fairly well now, with one caveat (see edit).
    – user9424
    Jan 26, 2021 at 12:14

1 Answer 1

3

While some TikZ wizard comes to explain the way, let me propose the ConTeXt way, explained in the Colors manual:

\setuppapersize[A6]
\startuseMPgraphic{shade}
%You could directly apply this with any fill operation
%but it's better to keep it separated for reuse
defineshade covershade
withshademethod "linear" 
withshadevector (dir 180) %play with angles to see what happens
%MetaPost understands colors differently
%Hence the white
withshadecolors (.3[white,green],.3[white,blue])
;
StartPage;
fill Page shaded covershade;
StopPage;
\stopuseMPgraphic
\definelayer[shade][state=repeat]
\setlayer[shade]{\useMPgraphic{shade}}
\setupbackgrounds[page][background=shade]
\starttext
\dorecurse{3}%
{
\samplefile{quevedo-es}
\samplefile{knuth}
}
\stoptext

And we have a nice background with no TikZ involved. :D

enter image description here

3
  • 1
    When you apply a background to the page you can use a overlay without the need for layer, i.e. you can remove the \definelayer and \setlayer settings and replace them with \defineoverlay[shade][\useMPgraphic{shade}]. Jan 26, 2021 at 22:26
  • @WolfgangSchuster But, unlike layers, overlays don't repeat themselves across pages, right? Or did I miss a key?
    – user226564
    Jan 26, 2021 at 22:27
  • Overlays are applied to each page but it works in your example only when I remove defineshade and apply the settings to the filled box itself. Jan 30, 2021 at 20:08

You must log in to answer this question.