我的目标是为我的文档设置一个包含平铺图像和水印的背景。奇数页和偶数页上的水印必须不同。
当我将其用作page
第setupbackgrounds
一个参数时,所有页面上确实都有背景图像和水印(但当然所有页面上都有相同的水印),即一切都按我预期的方式工作,但这不是我想要实现的结果。
但是,如果我改用leftpage
或rightpage
(作为区分奇数页和偶数页的第一步),我会丢失所有页面上的图像和水印:换句话说,该图层不再应用于任何地方。
这是一个最小(非)工作示例:
% Document main configuration
\setuppapersize[A4] % document page size
\setupbodyfont[10pt] % document default font size
% --- Font families definitions ---
\definefontfamily[myfont][serif][myfontname]
% --- Document Background ---
\define\mybgimg % macro for background image code
{\backgroundimage{1} % - 1 = tiled along x & y
{\paperwidth}{\paperheight} % - set width and height of the addition
{\externalfigure[bg.jpg]}} % - addition of a bg image
\define[1]\mywatermarkformat{{ % macro to format the watermark
\switchtobodyfont[myfont] % - set font family
\switchtobodyfont[105pt] % - set font size
\color[red]{#1} % - set color to text argument
}}
\definelayer[mybglayer] % define and name new layer for the bg
[x=0mm, y=0mm, % - from upper left corner of paper
width=\paperwidth, height=\paperheight, % - let the layer cover the full paper
repeat=yes% % - layer on all pages
]
\setlayer[mybglayer]{\mybgimg} % fill layer with bg image
\setlayer[mybglayer] % fill layer with watermark
[hoffset=0cm, voffset=23cm] % - placement from layer upper left corner
{\mywatermarkformat{foobar}} % - watermark text
\setupbackgrounds[page][background=mybglayer] % <--- OK : place the layer on all pages
% OR
\setupbackgrounds[leftpage][background=mybglayer]% <---- NOT OK : place nothing at all
% --- Document Content ---
\starttext
\input knuth
\page
\input knuth
\page
\input knuth
\page
\input knuth
\stoptext
我是 ConTeXt 的初学者,因此如果您在代码中发现一些可疑结构(与主要问题无关),请随时告诉我。
答案1
您必须将文档设置为双面。您还应该更好地处理虚假空格。
\setuppapersize[A4]
\setuppagenumbering[alternative=doublesided]
\definefontfamily[myfont][serif][TeX Gyre Pagella]
\setupbodyfont[myfont,105pt] % preload
\setupbodyfont[modern,10pt]
\define\mybgimg
{\backgroundimage{1}%
{\paperwidth}{\paperheight}%
{\externalfigure[cow]}}
\define[1]\mywatermarkformat
{{\switchtobodyfont[myfont,105pt]\color[red]{#1}}}
\definelayer
[page]
[width=\paperwidth,
height=\paperheight,
repeat=yes]
\definelayer[rightlayer][page]
\definelayer[leftlayer][page]
\setlayer
[rightlayer]
{\mybgimg}
\setlayer
[rightlayer]
[hoffset=0cm,voffset=23cm]
{\mywatermarkformat{right page}}
\setlayer
[leftlayer]
{\mybgimg}
\setlayer
[leftlayer]
[hoffset=0cm,voffset=23cm]
{\mywatermarkformat{left page}}
\setupbackgrounds[rightpage][background=rightlayer]
\setupbackgrounds[leftpage][background=leftlayer]
\starttext
\input knuth
\page
\input knuth
\page
\input knuth
\page
\input knuth
\stoptext