I took an example from another answer to a similar question (How to define a figure size so that it consumes the rest of a page?).
On a page of an exam paper I want the following:
Question
Quadpaper (light grey)
Maybe a remark like "review your answer".
So here is my MWE:
\documentclass[svgnames,a4paper]{report}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[margin=25mm]{geometry}
\usepackage{lipsum}
\newcommand{\currentsidemargin}{%
\ifodd\value{page}%
\oddsidemargin%
\else%
\evensidemargin%
\fi%
}
\begin{document}
\setlength{\parindent}{0mm} \setlength{\parskip}{6pt}
\newsavebox\mybox
\savebox{\mybox}[\textwidth][c]{ % The text for below the grid
\parbox{\textwidth}{
\textbf{\Huge Some text}
\lipsum[3]
}
}
\newlength\gnat
\settoheight{\gnat}{\usebox{\mybox}}
\addtolength{\gnat}{0.5\parskip}
\lipsum[2-5]% dummy text
\begin{tikzpicture}[overlay,remember picture]
% Helper nodes
\path (current page.north west) ++(\hoffset, -\voffset)
node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\paperwidth,
minimum height=\paperheight] (pagearea) {};
\path (pagearea.north west) ++(\leftmargin+\currentsidemargin,
-\topmargin-\headheight-\headsep+\gnat)
node[anchor=north west, shape=rectangle, inner sep=0,
minimum width=\textwidth, minimum height=\textheight] (textarea) {};
% Image
\path let \p0 = (0,0), \p1 = (textarea.south) in
node [inner sep=0pt,outer sep=0pt,anchor=north west] {%
\pgfmathsetmacro\imgheight{(\y0-\y1-0.5\gnat-mod(\y0-\y1-0.5\gnat,8mm))}%
\begin{tikzpicture}[remember picture,overlay]
\node[xshift=+0mm,yshift=1mm] at (\p0){
\begin{tikzpicture}%[overlay,remember picture]
\tikzset{dotted lines/.style={black, loosely dotted, thick}}
\draw[style=dotted lines,step=.8cm] (0,0) grid (160mm,\imgheight pt+24mm);
\end{tikzpicture}
};
\end{tikzpicture}
%}
};
\end{tikzpicture}
\vfill
\vfill
\usebox{\mybox}
%\the\gnat % To see the space
\end{document}
My question: Why do I have to add 24mm to the grid to get it fill the full available space?
[I will later add a test to check if the box is empty and then set \gnat to zero. Although any suggestions would be appreciated.]
\gnatto the the margin when calculating the position of tho\textareanode? – Caramdir Jun 24 '11 at 10:50textareanode is not placed where I expect it to be placed (add adrawto its options to see the outline). – Caramdir Jun 24 '11 at 10:59