在书籍 PDF 中,我使用各种图像作为多个页面的背景。在某些背景图像页面中,我希望图像是半透明的;因此,我在背景页面设置选项中使用不透明度设置。每个背景图像页面渲染都很好……直到我决定在第一页为这本书做封面艺术。我只想要一个渐变背景,在具有 alpha 通道的图像后面。我使用以下 tikzpicture 代码来执行此操作:
\begin{tikzpicture}[remember picture, overlay]
\path [left color = black,middle color = black!80, right color = gray!20] (current page.south west)rectangle (current page.north east);
\node[inner sep=0pt] (russell) at (10,-13)
{\includegraphics[width=\paperwidth, height=\paperheight]{some_image_with_transparent_background_here.png}};
\end{tikzpicture}%
此代码对于第一个封面页来说运行良好 - 但似乎弄乱了第一个图像背景页(发生在封面页的几页之外)。在第一个背景图像页上,它不遵守 0.10% 的不透明度设置;相反,页面呈现完全不透明。当我删除上面的代码时,不透明度设置适用于背景图像页,并按我想要的方式呈现半透明...当我将上面的代码放回文档中时,第一个背景图像页再次呈现完全不透明,不符合所需的 0.10% 不透明度设置。奇怪的是,上面的代码仅影响第一个背景图像页。第二、第三、第四等,根据给定的设置正确呈现。
如果有关系的话,我正在使用 XeLaTeX,并且我认为我所使用的所有软件包都与它紧密相关。
我做错了什么?我知道的 tikz 足以让我陷入麻烦。我根据网上的例子拼凑了这些。
MWE 包含首页封面和背景图像页,代码如下:
\documentclass[a4paper,12pt,twoside,]{book}
\usepackage[pages=some]{background}
\begin{document}
\newpage
% the PDF cover page
\begin{tikzpicture}[remember picture, overlay]
\path [left color = black,middle color = black!80, right color = gray!20] (current page.south west)rectangle (current page.north east);
\node[inner sep=0pt] (russell) at (10,-13)
{\includegraphics[width=\paperwidth, height=\paperheight]{some_image_with_transparent_background_here.png}};
\end{tikzpicture}%
\newpage
\thispagestyle{empty}
% first page that uses a background image after the cover page
\backgroundsetup{
scale=1,
placement=center,
color=black,
opacity=0.10,
angle=0,
contents={%
\includegraphics[width=\paperwidth]{some_image_here.png}}%
}
\BgThispage
Why is background image on this page not honoring the 0.10 percent opacity setting when the tikzpicture code is used on the first page? Yet it does honor the opacity setting when the tikzpicture code is removed on the first page ?
Also, I note that ONLY this first page is the page that does not honor the opacity setting. Any backgrounded page after this one returns to proper rendering with opacity settings honored. If you repeat this page for the next page, the desired opacity settings will render properly !
\end{document}
答案1
也许不是一个优雅的解决方案...但仍然是一个可行的解决方案:
在封面上,添加一个虚拟背景设置,并对 \BgThisPage 进行虚拟调用,然后在该虚拟调用之后什么都不做。
\BgThisPage 实际上不会在此页面渲染任何内容,因为某物需要在页面上才能由背景进行渲染。
使用此虚拟调用,则下次您确实需要某些背景内容时,将第二次调用 \BgThisPage ...,并且不透明度设置将得到遵守。
也许这不是一个合适的解决方案,但确实有效。我还在等待更好的解决方案,但我想分享一下,以防万一这篇文章没有添加任何内容。
这是对我有用的代码:
\documentclass[a4paper,12pt,twoside,]{book}
\usepackage[pages=some]{background}
\begin{document}
\newpage
% the PDF cover page
\begin{tikzpicture}[remember picture, overlay]
\path [left color = black,middle color = black!80, right color = gray!20] (current page.south west)rectangle (current page.north east);
\node[inner sep=0pt] (russell) at (10,-13)
{\includegraphics[width=\paperwidth, height=\paperheight]{some_image_with_transparent_background_here.png}};
\end{tikzpicture}%
%%
% Make a dummy call to \BgThisPage
%%%%%
\backgroundsetup{
scale=1,
placement=center,
color=black,
opacity=0.10,
angle=0,
contents={%
\includegraphics[width=\paperwidth]{some_image_here.png}}%
}
\BgThispage
\newpage
\thispagestyle{empty}
% first page that uses a background image after the cover page
% but now, this is the second call to \BgThisPage ... which
% seems to have flushed whatever was messing up opacity setting
% not being honored. This call will render at 0.10 transparent
\backgroundsetup{
scale=1,
placement=center,
color=black,
opacity=0.10,
angle=0,
contents={%
\includegraphics[width=\paperwidth]{some_image_here.png}}%
}
\BgThispage
The image now renders as desired with semi-transparent settings honored.
\end{document}
答案2
有趣的是,使用您的 MWE,我在 overleaf 上尝试了它。第二页背景确实遵守了不透明度设置 0.1。您在实际文档中放入的其他东西是否导致了此问题?