Diferente salida xelatex y lualatex (tikzpagenodes, tcolorbox y paquetes de fondo involucrados)
Estoy colocando una imagen en la parte superior de la página de aperturas de capítulos. La imagen debe ocupar todo el ancho de la página. El siguiente código funciona bien con LuaLaTeX
, pero cuando lo ejecuto XeLaTeX
(debe ejecutarse 3 veces para obtener el posicionamiento adecuado), la imagen se mueve al centro horizontal de la página. Por otras razones, tengo que ejecutar el documento con XeLaTeX
. ¿Qué debo cambiar en el código para ejecutar XeLaTeX
y obtener el resultado que se muestra LuaLaTeX
?
EDITAR Cambiado para usar una imagen de ejemplo. El encabezado cambiará para respetar lo que muestran las imágenes; pero el efecto de usar XeLaTeX
es el mismo.
\documentclass{book}
%%% Include image in chapter opening
\RequirePackage{tikzpagenodes}
%%% fill rectangle with image uisng tcolorbox
%%% https://tex.stackexchange.com/a/219424/2483
\RequirePackage{tcolorbox}
\tcbuselibrary{skins}
\usetikzlibrary{calc}
\usetikzlibrary{fadings}
%%% For the background
%%% https://tex.stackexchange.com/a/86702/2483
\usepackage[pages=some]{background}
\newlength{\bleendlength}
\setlength{\bleendlength}{5mm}
\newcommand{\chapimage}[1]{%
\backgroundsetup{scale=1,placement=top,contents={
\tikz[remember picture,overlay] {%
\path[fill overzoom image=example-image-a, fill image opacity=1, path fading=east, fading angle=-30]
($(current page.north west)+(-\bleendlength, \bleendlength)$)
rectangle
($(current page.north east)+(\bleendlength, -6cm)$);
}
}
}
}
\begin{document}
\chapter{My first chapter}
\label{cha:my-first-chapter}
\chapimage{}\BgThispage
\end{document}
Salida correcta con LuaLaTeX
:

Salida incorrecta con XeLaTeX
:

Respuestas
El valor pasado a background
la opción contents
(almacenado en \Background@Contents
) ya está escrito dentro de un tikzpicture
. Y anidar tikzpicture
es un comportamiento indefinido. Ver la implementación de \bg@material
en background
v2.1, 2014/03/04:
\newcommand\bg@material{%
\begin{tikzpicture}[remember picture,overlay,scale=\Background@Scale]
\node[
rotate=\Background@Angle,
scale=\Background@Scale,
opacity=\Background@Opacity,
anchor=\Background@NodeAnchor,
xshift=\Background@HShift,
yshift=\Background@VShift,
color=\Background@Color,
inner sep=0pt
]
at (\Background@Position) [\Background@Anchor]
{\Background@Contents};
\end{tikzpicture}}%
Un intento bruto es redefinir \bg@material
.
% this example produces the same output with pdftex, xetex, and luatex
\documentclass{book}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usetikzlibrary{calc, fadings}
\usepackage[pages=some]{background}
\newlength{\bleendlength}
\setlength{\bleendlength}{5mm}
\makeatletter
\renewcommand\bg@material{%
\tikz[remember picture,overlay] {%
\path[fill overzoom image=example-image-a, fill image opacity=1, path fading=east, fading angle=-30]
($(current page.north west)+(-\bleendlength, \bleendlength)$)
rectangle
($(current page.north east)+(\bleendlength, -6cm)$);
}%
}%
\makeatother
\begin{document}
\chapter{My first chapter}\label{cha:my-first-chapter}
\BgThispage
\end{document}
Las mejores soluciones van desde una mejor redefinición, utilizando otro paquete de fondo, hasta proporcionar un estilo de página especial establecido por \chapter
(supongamos que desea tener un efecto de fondo similar para la página de título del capítulo).