The marginnote package offers the \marginnote macro. I use this inside a tikzpicture environment to place notes into the margin.
While this works without problems when compiling with pdfLaTeX, this gives horizontal shifts when compiling with XeLaTeX.
Consider the following MWE:
\documentclass{article}
\usepackage{marginnote}
\usepackage{tikz}
\usepackage[showframe]{geometry}
\begin{document}
This line\marginnote{ABC} contains a margin note.
\begin{tikzpicture}
\fill[red] (-1,-1) rectangle (1,1);
\node[right] at (1,0) {This line\marginnote{ABC} contains a margin note.};
\end{tikzpicture}
\end{document}
Compilation (twice) with pdfLaTeX (using MiKTeX on Windows) gives the expected result:
Compilation with XeLaTeX (using MiKTeX on Windows) gives shifts the second note inside the tikzpicture:
Can this code be modified to compile correctly for pdfLaTeX and XeLaTeX?

