我正在将图像放置在章节开头页面的顶部。图像应填满整个页面宽度。下面的代码在 下运行良好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}
答案1
background
传递给选项的值contents
(存储在 中\Background@Contents
)已在 中排版tikzpicture
。嵌套是未定义的行为。请参阅v2.1,2014/03/04中tikzpicture
的 实现:\bg@material
background
\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
(假设您希望每个章节标题页都有类似的背景效果)。