I use fancyhdr to create custom headers and footers. I also use textpos and Tikz to embellish those headers and footers.
I want to use textpos
with absolute positioning instead of tikz current page
because it does not require multiple compilation.
Now I declare several page style with variable header/footer heights. I would like to add a custom geometry for the page not overlapping the header/footer.
I got here a MWE
% -*- latex -*-
\documentclass[a4paper]{article}
\usepackage{fontspec}
\usepackage{tikz}
\usepackage{fancyhdr}
\usepackage{blindtext}
\usepackage[absolute,overlay]{textpos}
\usepackage{geometry}
\makeatletter
\newcommand{\header@first}{%
\begin{textblock*}{\paperwidth}[0,0](0pt, 0pt)
\begin{tikzpicture}
\node [rectangle, draw=red,
anchor=north,
minimum width=\paperwidth-\pgflinewidth,
minimum height=5cm] (box) at (0.5\paperwidth,0mm) {};
\end{tikzpicture}
\end{textblock*}
}%
\newcommand{\footer@first}{%
\begin{textblock*}{\paperwidth}[0,1](0pt, \paperheight)
\begin{tikzpicture}
\node [rectangle, draw=red,
anchor=south,
minimum width=\paperwidth-\pgflinewidth,
minimum height=8cm] (box) at (0.5\paperwidth,\paperheight) {};
\end{tikzpicture}
\end{textblock*}
}%
\fancypagestyle{firstpage}{%
\fancyhf{}
\lhead{} \chead{\header@first} \rhead{}
\lfoot{} \cfoot{\footer@first} \rfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\newgeometry{top=5cm, bottom=8cm, hmargin={1cm, 1cm}, textwidth=19cm}
}
\fancypagestyle{otherpage}{%
\fancyhf{}
\lhead{} \chead{} \rhead{}
\lfoot{} \cfoot{} \rfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\newgeometry{top=1cm, bottom=1cm, hmargin={5cm, 5cm}, textwidth=11cm }
}
\pagestyle{otherpage}
\makeatother
\begin{document}
\thispagestyle{firstpage}
\Blinddocument
\newpage
\pagestyle{fancy}
\blinddocument
\end{document}
As one can see the newgeometry
is not well defined per page style.
BTW I am not sure that I should define a geometry in a \fancypagestyle
command.
Is there a way to do this properly?
TIA.
\AtBeginShipoutNext{\loadgeometry{otherpage}}
and similar stuff but no can do. I seriously wonder if changing geometry within a fancy header is really working.