Ok, I think I have something, but am not exactly sure of it; the fix seems to be this:
\ifx\CROP@size\undefined
\typeout{CROP@size undefined}
\else
\typeout{CROP@size defined}
% must set via newlength so it survives descent into tikzpicture!
\setlength\gparindent{\parindent}
\setlength\gbaselineskip{\baselineskip}
\def\current@textarea@left{(1in+\hoffset+\currentsidemargin-\Gm@lmargin-\gparindent)}
\def\current@textarea@top{(1in+\voffset+\topmargin+\headheight+\headsep)+2*\[email protected]\gbaselineskip}
\fi
... that is, if crop
is loaded, redefine \current@textarea@left
and \current@textarea@top
from tikzpagenodes
, so the left is adjusted by \Gm@lmargin-\gparindent
and the right by 2*\[email protected]\gbaselineskip
- where \Gm@l
/tmargin
are margins via the geometry
package.
The \gparindent
and \gbaselineskip
are "globalised" versions of parindent/baselineskip - as lengths - otherwise they won't propagate when the above definitions run inside tikzpicture
(which resets parindent/baselineskip). The Gm@ margins make sense, but I have no idea why there is this displacement in there to begin with - I found the fix values via trial/error, so caveat emptor.
The code below has some extra debug stuff, and it outputs something like this:
Seems there is a tiny amount of bleed too - which is nice; also, all seems to work if you just comment the crop
lines, as well.
The code:
\documentclass[10pt,twoside,openright]{book}
\usepackage[
paperwidth=15cm,
paperheight=20cm,
outer=3.5cm,
inner=2.5cm,
top=2.5cm,
bottom=3.5cm
]{geometry}
\usepackage[a4,center]{crop}
\crop[cam,info]
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage{tikz}
\usetikzlibrary{external,calc}
\usepackage{tikzpagenodes}
\makeatletter
\newlength\gparindent
\newlength\gbaselineskip
\ifx\CROP@size\undefined
\typeout{CROP@size undefined}
\else
\typeout{CROP@size defined}
% from tikzpagenodes:
% NB: \parindent, \baselineskip seem to dissapear inside \sectioncolouration
% \let\gparindent\parindent% NO
% \xdef\gparindent{\parindent}% NO!
% must set via newlength so it survives descent into tikzpicture!
\setlength\gparindent{\parindent}
\setlength\gbaselineskip{\baselineskip}
\typeout{gparindent-Start \the\gparindent}%
\def\current@textarea@left{(1in+\hoffset+\currentsidemargin-\Gm@lmargin-\gparindent)}
\def\current@textarea@top{(1in+\voffset+\topmargin+\headheight+\headsep)+2*\[email protected]\gbaselineskip}
% no need to repeat this:
% \@newtikzpagenode{current page text area}{%
% \def\southwest{\pgfpoint{\current@textarea@left}{\paperheight-\current@textarea@top-\textheight}}%
% \def\northeast{\pgfpoint{\current@textarea@left+\textwidth}{\paperheight-\current@textarea@top}}%
% }
\fi
\makeatother
\newcommand*\sectioncolouration[1]{%
\begin{tikzpicture}[baseline=(a.base), overlay, remember picture, inner xsep=0pt, outer sep=0pt]%
\typeout{gparindent-In-Sect-Col \the\gparindent}%
\node (a) {\phantom{\normalfont\Large\bfseries Xy}};
\path [fill=blue, fill opacity=.2, even odd rule]
(current page.west |- a.north) -| (current page.east |- a.south) -| cycle
(current page text area.west |- a.north) -| (current page text area.east |- a.south) -| cycle;
% (current page text area.south west) -| (current page text area.north east) -| cycle; % debug
\draw[red] (current page text area.north east) rectangle (current page text area.south west); % debug
\ifodd\value{page}
\node at (a -| {$(current page text area.east)!1/2!(current page.east)$}) {#1};
\else
\node at (a -| {$(current page text area.west)!1/2!(current page.west)$}) {#1};
\fi
\end{tikzpicture}}
\titleformat{\section}[hang]{%
\typeout{gparindent-Sect \the\gparindent}%
\setlength\gparindent{\parindent}%
\setlength\gbaselineskip{\baselineskip}%
\normalfont\Large\bfseries\color{black!90}%
}{\thesection}{1.5em}{\tikzexternaldisable\sectioncolouration{\Alph{section}}}[\tikzexternalenable]
\begin{document}
\frontmatter
\mainmatter
\part{Introduction}
\chapter*{The first chapter - without thinking anything else}
\newpage
\section{The first section - and some more text inside; and some more text inside; and some more text inside}
% debug
\begin{tikzpicture}[remember picture,overlay]
\draw[thick] (current page text area.north east) rectangle (current page text area.south west) ;
\draw[thick] (current page text area.east) rectangle ($(current page text area.west)+(0,1)$) ;
\end{tikzpicture}
\noindent
Blah, blah, blah... \lipsum[1-3]
% \newpage
\section{This section starts on an odd page}
Some text\dots
\end{document}
geometry
. It thinks that your paper is 15x20cm when it is really 21x29.7cm. However, I'm losing the crop marks when I do this.geometry
has ashowcrop
of its own? That works fine...geometry
and losing cropmarks; had no idea aboutgeometry
'sshowcrop
- but I'd prefer to get this working with thecrop
package (it was used in the original template I'm using).