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. Commented Jun 23, 2020 at 11:54
  • what's going on is easy: the color overprints the crop marks. But I don't see an easy fix. Commented Jun 23, 2020 at 13:07
  • why not use tikz to "set" the page
    – js bibra
    Commented Jun 23, 2020 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. Commented Jun 26, 2020 at 0:08

1 Answer 1

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 :) Commented Jun 24, 2020 at 13:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .