I want to define a tikz node called current grid area
based on the nodes defined by the tikzpagenodes
package. This node is a rectangle that contains the 4 nodes defined in the package; current page footer
, current page header
, current page text area
and current page marginpar
:
The north of the grid area should be the north of the header; the south should be the south of the footer. The east and west depend of the recto/verso page. In odd pages the west should be west of the text area and the east of the marginpar. In the even pages the west is the west of marginpar and the east the is the east of the text area.
I extract the coordinate values of the corners of each area save them in global macros like \gl@globalgridareaw
, \gl@globalgridareae
....
Then I build the node using the code to build current page
in pgfmoduleshapes.code.tex
.
Is part I don't understand very well :-),
% Special current grid area bounding box rectangle: \expandafter\def\csname pgf@sh@ns@current grid area\endcsname{rectangle} \expandafter\def\csname pgf@sh@np@current grid area\endcsname{% \def\southwest{\pgfqpoint{\gl@globalgridareaw}{\gl@globalgridareas}}% \def\northeast{\pgfqpoint{\gl@globalgridareae}{\gl@globalgridarean}}% } % % TODO: Should I redefine this? \expandafter\def\csname pgf@sh@nt@current grid area\endcsname{{1}{0}{0}{1}{0pt}{0pt}} \expandafter\def\csname pgf@sh@pi@current grid area\endcsname{pgfpageorigin} }
As the example bellow show the the node is not correctly defined. It seems that some offset should be added.
\documentclass{article}
\usepackage{geometry}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\makeatletter
\newcommand{\calculateparameters}{
\noindent\tikz[remember picture,overlay]{\path (current page header area.north);%
\pgfgetlastxy{\gl@discard}{\gl@gridarean}
\path (current page footer area.south);
\pgfgetlastxy{\gl@discard}{\gl@gridareas}
\global\let\gl@globalgridareas\gl@gridareas%
\global\let\gl@globalgridarean\gl@gridarean%
}
\checkoddpage
\ifoddpage
\noindent\tikz[remember picture,overlay]{
\path (current page marginpar area.east);
\pgfgetlastxy{\gl@gridareae}{\gl@discard}
\path (current page text area.west);
\pgfgetlastxy{\gl@gridareaw}{\gl@discard}
\global\let\gl@globalgridareaw\gl@gridareaw%
\global\let\gl@globalgridareae\gl@gridareae%
}
\else
\tikz[remember picture,overlay]{
\path (current page marginpar area.west);
\pgfgetlastxy{\gl@gridareaw}{\gl@discard}
\path (current page text area.east);
\pgfgetlastxy{\gl@gridareae}{\gl@discard}
\global\let\gl@globalgridareaw\gl@gridareaw%
\global\let\gl@globalgridareae\gl@gridareae%
}
\fi
% Special current grid area bounding box rectangle:
\expandafter\def\csname pgf@sh@ns@current grid area\endcsname{rectangle}
\expandafter\def\csname pgf@sh@np@current grid area\endcsname{%
\def\southwest{\pgfqpoint{\gl@globalgridareaw}{\gl@globalgridareas}}%
\def\northeast{\pgfqpoint{\gl@globalgridareae}{\gl@globalgridarean}}%
}
% % TODO: Should I redefine this?
\expandafter\def\csname pgf@sh@nt@current grid area\endcsname{{1}{0}{0}{1}{0pt}{0pt}}
\expandafter\def\csname pgf@sh@pi@current grid area\endcsname{pgfpageorigin}
}
\makeatother
\begin{document}
\calculateparameters%
\noindent\tikz[<-,remember picture,overlay] {%
\draw[red] (current grid area.south west) rectangle (current grid area.north);
}%
\tikz[remember picture,overlay] {%
\draw [blue,line width=2mm]
(current page.south west)
rectangle
(current page.north east);
\draw [green]
(current page text area.south west)
rectangle
(current page text area.north east);
\draw [yellow]
(current page marginpar area.south west)
rectangle
(current page marginpar area.north east);
\draw [red]
(current page header area.south west)
rectangle
(current page header area.north east);
\draw [orange]
(current page footer area.south west)
rectangle
(current page footer area.north east);
}%
\end{document}