# pdflscape and tikzpagenodes problem

I am having problems getting the tikzpagenodes package to work with the pdflscape package. I want to access the nodes (current page text area) and (current page marginpar area) when rotating a page to landscape, but I am surprised by the results.

My problem is somewhat similar to the one in this post, though for me the (current page) node works as expected.

Here is an MWE where I try to draw the outline of the node, both before and after starting the rotation. I am compiling this with pdflatex and also with lualatex in MiKTeX 2.9 (I actually probably need to use lualatex for memory reasons).

\documentclass{article}

\usepackage{pdflscape}
\usepackage{tikzpagenodes}
\usepackage{fancyhdr}
\usepackage{blindtext}

\fancypagestyle{sideways}{
\renewcommand{\footrulewidth}{0pt}
\fancyhf{}
\fancyhead{\tikz [remember picture,overlay] \draw [red] (current page text area.south west) rectangle (current page text area.north east);}
}

\begin{document}

\begin{landscape}
\thispagestyle{sideways}
\blindtext
\end{landscape}

\clearpage

\thispagestyle{sideways}
\begin{landscape}
\blindtext
\end{landscape}

\end{document}


The output I am seeing is that the text is correctly placed, while the tikz node is much too small:

The reason I am putting the \tikz\draw inside a fancyheading is that I want to use this for placing headers and footers on a landscape page (yes, I know I probably shouldn't...).

I have also observed the 'inverse' of this behaviour, where the (current page text area) is placed correctly, and the text is occupying the region now outlined by the (current page text area) node, but I was not able to reproduce this behaviour in a reasonably small MWE.

-

I think I'm getting a handle on this now.

There is a quirk in the packages lscape/pdflscape: they change \textheight but not \textwidth. This is a design choice, apparently. Nevertheless, it confuses tikzpagenodes, which uses both lengths to define its nodes.

I have a solution that solves my particular problem: redefining the landscape environment by resetting \textheight to its original, non-rotated, value. I cannot detect any side-effects, but I'm holding off on accepting the answer in case someone else does, or perhaps can offer a more satisfying solution. Not that this question has generated any interest so far..

Here is my (now, working) MWE:

\documentclass{article}

\usepackage{lscape}
\usepackage{tikzpagenodes}
\usepackage{fancyhdr}
\usepackage{blindtext}

\fancypagestyle{sideways}{
\renewcommand{\footrulewidth}{0pt}
\fancyhf{}
\begin{tikzpicture}[remember picture,overlay]
\draw [red] (current page text area.south west) rectangle
(current page text area.north east);
\draw [green] (current page header area.south west) rectangle
(current page header area.north east);
\draw [blue] (current page footer area.south west) rectangle
(current page footer area.north east);
\draw [black] (current page marginpar area.south west) rectangle
(current page marginpar area.north east);
\end{tikzpicture}
}
}

% This fixes the \textheight problem
\newlength{\oldtextheight}
\let\oldlandscape\landscape
\def\landscape{\setlength{\oldtextheight}{\textheight}\oldlandscape\setlength{\textheight}{\oldtextheight}}

\begin{document}
\thispagestyle{sideways}
\blindtext

{\huge\bf Text height = \the\textheight}

{\huge\bf Text width = \the\textwidth}

\begin{landscape}
\thispagestyle{sideways}
\blindtext

{\huge\bf Text height = \the\textheight}

{\huge\bf Text width = \the\textwidth}

\end{landscape}

\end{document}


-
Your new landscape definition will throw an error if you have \includegraphics[height=\textheight]{whatever.png} within a landscape environment. Something like ! Output loop---100 consecutive dead cycles. While \includegraphics[width=\textwidth]{whatever.png} will continue to work. Perhaps there is a way to correct this. Note it seems parameter height is the culprit here-being disabled. – macmadness86 Mar 22 at 12:56