TransWikia.com

Opacity not present on first page with package 'atbegshi' when using xelatex

TeX - LaTeX Asked by Pieter Stroobants on October 2, 2021

I am creating my draftmarks using the package tikz on the XeLaTeX engine. In order to place this mark on every page I use the package atbegshi. Consider the following example:

documentclass[a4paper]{article}
usepackage{atbegshi}
usepackage{tikz}

AtBeginShipout{AtBeginShipoutUpperLeft{
    begin{tikzpicture}[remember picture,overlay]
    node [rotate=54.85,scale=7,text opacity=0.1,black]
    at (current page.center) {Draftmark};
    end{tikzpicture}
}}

begin{document}
Page 1
newpage
Page 2
newpage
Page 3
end{document}

When compiling this example using the PDFLaTeX engine the resulting PDF is created with a mark (with the correct opacity) on every page. On XeLaTeX the opacity of this mark disappears on the first page but not on any subsequent pages where the opacity remains intact. When using an alternative package like everypage the resulting PDF is created as requested but this package is not supported by my publisher.

Can anyone reproduce this behavior and offer a solution?

One Answer


Attention! In LaTeX 2020-10-01 and newer an additional rule could be needed to order the code in the hook if opacity is used on the first page. See https://tex.stackexchange.com/a/581404/2388


The problem is that your command is "outside" the shipout box and too early. And so the opacity settings are not added to the first page. The documentation of atbegshi shows an example how to add specials to the shipout box, but imho easier is to use the opacity somewhere on the first page:

documentclass[a4paper]{article}
usepackage{atbegshi}
usepackage{tikz,lipsum}


AtBeginShipout{AtBeginShipoutUpperLeft
{
    begin{tikzpicture}[remember picture,overlay]
    node [rotate=54.85,scale=7,text opacity=0.1,black]
    at (current page.center) {Draftmark};
    end{tikzpicture}
}}

begin{document}
Page 1tikz[overlay]path[opacity=0.1](0,0); 
newpage
Page 2 
newpage
Page 3
end{document}

With the next latex version (that you can test now with xelatex-dev) you could use the new shipout/foreground hook:

documentclass[a4paper]{article}
usepackage{tikz,lipsum}


AddToHook{shipout/foreground}
{
 put(0,0)
   {
    begin{tikzpicture}[remember picture,overlay]
    node [rotate=54.85,scale=7,text opacity=0.1,black]
    at (current page.center) {Draftmark};
    end{tikzpicture}
   }
}


begin{document}
Page 1
newpage
Page 2 
newpage
Page 3
end{document}

Correct answer by Ulrike Fischer on October 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP