異なる出力xelatexおよびlualatex(tikzpagenodes、tcolorbox、およびバックグラウンドパッケージが含まれます)

Aug 17 2020

章の冒頭のページの上部に画像を配置しています。画像はすべてのページ幅を埋める必要があります。以下のコードはで正常LuaLaTeXに動作していますが、で実行するとXeLaTeX(適切な位置を取得するには、3回実行する必要があります)、画像はページの水平方向の中央に移動します。他の理由で、ドキュメントをで実行する必要がありますXeLaTeX。で実行しXeLaTeX、で示される出力を取得するには、コードを何に変更する必要がありLuaLaTeXますか?

編集サンプル画像を使用するように変更されました。ヘッダーは、表示される画像を尊重するように変更されます。しかし、使用の効果はXeLaTeX同じです。

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

正しい出力LuaLaTeX

誤った出力XeLaTeX

回答

1 muzimuzhiZ Aug 17 2020 at 22:17

backgroundのオプションに渡された値contents(に格納されている\Background@Contents)は、すでにtikzpicture。内にタイプセットされています。また、ネストtikzpictureは未定義の動作です。実装を参照してください\bg@materialではbackgroundV2.1、2014年3月4日に:

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

野蛮な試みは、を再定義すること\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}

より優れたソリューションは、別の背景パッケージを使用したより良い再定義から、によって設定された特別なページスタイルの提供まで多岐にわたり\chapterます(章のタイトルページごとに同様の背景効果を持たせたいとします)。