1

Using the tikzpagenodes package to position elements in the page, I noticed that when loading the crop package, XeLaTeX and LuaLaTeX have different behaviour.

XeLaTeX incorrectly calculates the current page node coordinates. To get the correct coordinates the current page node should be shifted using hoffset and voffset.

The MWE below show, two rectangles covering the current page node. The blue one is the node calculated by tikzpagenodes; the red one has been shifted to have the correct rectangle with 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}

Correct output with LuaLaTeX:

enter image description here

Incorrect output with XeLaTeX: enter image description here

0

I guess this is caused by a typo in pgf's driver file for xetex, and the problem has been reported to pgf, see https://github.com/pgf-tikz/pgf/issues/909. Package crop sets non-zero \hoffset and \voffset, which uncover the problem.

The following code snippet can be used as a short-term workaround.

% after tikz is loaded
\usepackage{iftex}

\makeatletter
\ifXeTeX
  \def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfqpoint{\hoffset}{\voffset}}
\fi
\makeatother

A full example:

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

enter image description here

PS: Node current page is directly provided by tikz, so there is no need to load tikzpagenodes package.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.