Diversi output xelatex e lualatex (tikzpagenodes, tcolorbox e pacchetti background coinvolti)

Aug 17 2020

Sto posizionando un'immagine nella parte superiore della pagina delle aperture dei capitoli. L'immagine dovrebbe riempire tutta la larghezza della pagina. Il codice seguente funziona correttamente con LuaLaTeX, ma quando lo eseguo con XeLaTeX(dovrebbe essere eseguito 3 volte per ottenere il posizionamento corretto) l'immagine viene spostata al centro orizzontale della pagina. Per altri motivi, devo eseguire il documento con XeLaTeX. Cosa dovrei cambiare nel codice con cui eseguire XeLaTeXe ottenere l'output mostrato con LuaLaTeX?

EDIT Modificato per utilizzare un'immagine di esempio. L'intestazione cambierà per rispettare le immagini mostrate; ma l'effetto dell'uso XeLaTeXè lo stesso.

\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}

Correggere l'output con LuaLaTeX:

Output errato con XeLaTeX:

Risposte

1 muzimuzhiZ Aug 17 2020 at 22:17

Il valore passato backgroundall'opzione di contents(memorizzato in \Background@Contents) è già scritto all'interno di un file tikzpicture. E l'annidamento tikzpictureè un comportamento indefinito. Vedere l'implementazione di \bg@materialin backgroundv2.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 tentativo brutale è quello di ridefinire \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}

Le soluzioni migliori vanno da una migliore ridefinizione, utilizzando un altro pacchetto di sfondo, alla fornitura di uno stile di pagina speciale impostato da \chapter(supponiamo che tu voglia avere un effetto di sfondo simile per il frontespizio del capitolo).