使用tikzpagenodes
包在页面中定位元素,我注意到在加载crop
包时XeLaTeX
有LuaLaTeX
不同的行为。
XeLaTeX
错误地计算了current page node
坐标。要获得正确的坐标,current page node
应使用hoffset
和移动voffset
。
下面的 MWE 显示,两个矩形覆盖了current page node
。蓝色的是 计算的节点tikzpagenodes
;红色的已被移动以获得正确的矩形XeLaTeX
。
\documentclass{article}
\usepackage{calc}
\usepackage[
%
paperwidth = 210mm,
paperheight = 270mm,
includefoot,
includemp,
nomarginpar,
% textwidth
% textheight
% marginparwidth
% marginparsep
inner = 19.2mm+10mm,
outer = 19.2mm+10mm,
top = 14.6mm,
bottom = 10.8mm,
bindingoffset = 5.4mm,
% showcrop
]%
{geometry}
\usepackage%
[
cam,
width = 230mm,
height = 290mm,
center]%
{crop}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\begin{document}
\tikz[remember picture,overlay] {%
\draw [blue,line width=2mm]
(current page.south west)
rectangle
(current page.north east)
;
\draw [red,line width=2mm]
($(current page.south west)+ (-\hoffset, \voffset)$)
rectangle
($(current page.north east)+ (-\hoffset, \voffset)$)
;
}%
\end{document}
正确输出为LuaLaTeX
:
答案1
我猜这是由于 xetex 驱动程序文件中的拼写错误造成的pgf
,并且该问题已报告给pgf
,请参阅https://github.com/pgf-tikz/pgf/issues/909。包crop
设置非零\hoffset
和\voffset
,从而揭示了问题。
以下代码片段可用作短期解决方法。
% after tikz is loaded
\usepackage{iftex}
\makeatletter
\ifXeTeX
\def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfqpoint{\hoffset}{\voffset}}
\fi
\makeatother
完整示例:
\documentclass{article}
\usepackage{calc}
\usepackage[
paperwidth = 210mm,
paperheight = 270mm,
includefoot,
includemp,
nomarginpar,
% textwidth
% textheight
% marginparwidth
% marginparsep
inner = 19.2mm+10mm,
outer = 19.2mm+10mm,
top = 14.6mm,
bottom = 10.8mm,
bindingoffset = 5.4mm,
% showcrop
]%
{geometry}
\usepackage[
cam,
width = 230mm,
height = 290mm,
center
]%
{crop}
\usepackage{tikz}
\usepackage{iftex}
\makeatletter
\ifXeTeX
\def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfqpoint{\hoffset}{\voffset}}
\fi
\makeatother
\begin{document}
\tikz[remember picture,overlay]
\draw [blue,line width=2mm]
(current page.south west) rectangle (current page.north east);
\end{document}
PS: Nodecurrent page
直接由 提供tikz
,所以不需要加载tikzpagenodes
包。