Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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{\headrulewidth}{0pt}
    \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:

Result

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.

share|improve this question

1 Answer 1

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{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
    \fancyhf{}
    \fancyhead{
        \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}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.