I have a document which pulls in an external .tex file which is procedurally generated from a database and then interpreted into a multiple page table-like graphic written in TikZ.
However, when I hit a pagebreak I need to be able to add a header line much like longtable does. At the moment I'm using the everypage package, but that is really suboptimal because it doesn't play very nice with memoir, destroys my margins, adds a third reference to deal with (separate from both memoir and TikZ current page positioning). It also runs its code after the page has been executed (as far as I can tell?) which makes it difficult to reference things that happened on the previous page.
I have tried to read longtable but didn't get very far—it's impressive but a bit cryptic without guidance.
What is the correct way to implement a longtable-like repeating header for a table-shaped graph?
Here's an MWE of something I tried:
In theory, this should check each time it makes an \exampleblock to see if there's a header on the page, and if not, then it adds one. It works fine on the first page, but is always two blocks too low after that—I don't really know why.
% !TEX TS-program = xelatex
\documentclass[showtrims]{memoir}
\usepackage{tikz}
\setstocksize{11in}{8.5in}
\settrimmedsize{8.5in}{5.5in}{*}
\settrims{1in}{1in}
\setulmarginsandblock{1in}{1in}{*}
\setlrmarginsandblock{1in}{.75in}{*}
\checkandfixthelayout
\newcounter{headeronpage}
\newcommand\exampleblock{\vfill%
\ifnum\value{headeronpage}<\value{page}%
\headerthing\vfill\fi%
\noindent\tikz\draw(0,0)rectangle%
(\linewidth,12ex)node[pos=.5]%
{I'm a fancy TikZ drawing!};%
}
\newcommand\headerthing{%
\setcounter{headeronpage}{\value{page}}%
\noindent\tikz\draw (0,0)%
rectangle (\linewidth,4ex)%
node[pos=.5]{I'm a header thing!};%
}
\begin{document}
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\exampleblock
\end{document}
How is this challenge handled in packages like longtable?
Just to clarify: I know fancyhdr and stuff (though don't know how they work under the hood), what I'm trying to do isn't that kind of header, but more of a long table.
tikzpictureinside afancyhdr, but that sounds like a bit of a margin calculating nightmare... I'd much prefer if I could somehow have it actually inside the typeblock—is that impossible? How did you solve this problem when you wrote longtable? – Ryan May 12 '15 at 09:08longtablereplaces the standard output routine with its own so it takes control of the full page makeup including headers footers etc, and also why it doesn't work with say multicol (as that is doing the same) but also note that the longtable headers do not depend on the table content as they are set at a different time. (the dependency on column widths is handled indirectly and requires multiple latex runs) – David Carlisle May 12 '15 at 09:21\pagetotalto measure if there's enough space left over for another block, and insert a\headerthingif there's not enough space? – Ryan May 12 '15 at 09:27needspace, but couldn't seem to get it to work. I may have a solution now though. – Ryan May 12 '15 at 09:43