เอาต์พุต 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/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}}%

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

โซลูชัน Nicer มีตั้งแต่การกำหนดค่าใหม่ที่ดีขึ้นโดยใช้พื้นหลังอื่น ๆ ไปจนถึงการจัดเตรียมรูปแบบหน้าพิเศษที่กำหนดโดย\chapter(สมมติว่าคุณต้องการให้มีเอฟเฟกต์พื้นหลังที่คล้ายกันในหน้าชื่อบท)