2

I have created a document where some pages have a background color. I would like the pages to have crop marks, using the "showcrop" option of the package geometry (I do not want to use the "crop" package, for some reasons). The following MWE shows that the crop marks are missing in the colored pages.

\documentclass{book}

\usepackage{lipsum}
\usepackage{xcolor}

\usepackage{geometry}
\geometry{paper=a4paper, layoutwidth=170mm, layoutheight=240mm, layoutvoffset= 20mm, layouthoffset= 20mm, showcrop=true}

\begin{document}

\lipsum
\newpage \pagecolor{yellow}
\lipsum
\newpage \nopagecolor
\lipsum

\end{document}

Would anyone have any idea what is going on, and how to fix it ?

PS : it is not the same question as Color in bleed using pagecolor and crop : I am not using the crop package !

4
  • Using pdflatex or lualatex, I can reproduce your problem. Using xelatex, your problem is not reproducible but the \nopagecolor has no effect. Jun 23 '20 at 11:54
  • what's going on is easy: the color overprints the crop marks. But I don't see an easy fix. Jun 23 '20 at 13:07
  • why not use tikz to "set" the page
    – js bibra
    Jun 23 '20 at 14:03
  • @js bibra : yes, that is what I ended up doing, using tikz to create a colored rectangle that is bigge than the page but smaller than the crop marks, but that did not answer my question l how to create a background colored page that does not hide the crop marks. Jun 26 '20 at 0:08
2

The following is a bit clumsy but the result seems to be ok. The idea is to use the definition of showcrop from the geometry source combined with a custom page coloring approach with a zero-width zero-height colored \vrule, the definition of which is copied from the crop package. When you draw the vrule before the geometry crop marks the color does not overlap the marks.

Because I couldn't find out how to undo the \AtBeginShipout definition for subsequent pages without color, the \nopagecolorcrop command just sets the color of the rule to white.

\documentclass{book}

\usepackage{lipsum}
\usepackage{xcolor}

\usepackage{geometry}
\usepackage{atbegshi}
\geometry{paper=a4paper, layoutwidth=170mm, layoutheight=240mm, layoutvoffset= 20mm, layouthoffset= 20mm}

\makeatletter
\def\mypagecolor{white}
\AtBeginShipout{\setbox\AtBeginShipoutBox=\vbox to\z@{\vskip-1in\vbox{%
        \rlap{\smash{{\color{\mypagecolor}\hskip\dimexpr -\hoffset-1in\relax\vrule width\paperwidth height\z@ depth\paperheight}}}%
        \baselineskip\z@skip\lineskip\z@skip\lineskiplimit\z@
        \vskip1in%
        \Gm@pageframes\box\AtBeginShipoutBox}}}
\newcommand{\pagecolorcrop}[1]{
    \def\mypagecolor{#1}
}
\newcommand{\nopagecolorcrop}{%
    \def\mypagecolor{white}%
}
\Gm@showcroptrue
\makeatother

\begin{document}
\lipsum
\newpage \pagecolorcrop{yellow}
\lipsum
\newpage \nopagecolorcrop
\lipsum
\end{document}

enter image description here

1
  • Thanks a lot, impressive answer !! I can reproduce your solution, it works for me :) Jun 24 '20 at 13:37

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.