Graphics, Figures & Tablestabu | Dynamic long Table Headings

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
GerlofVito
Posts: 27
Joined: Wed May 16, 2012 8:24 pm

tabu | Dynamic long Table Headings

Post by GerlofVito »

I would like to create a 'longtabu' with dynamic headers. 'Longtabu' uses 'longtable', so I think the problem/solution applies to both.

I am using 'datatool' to create a database in the LaTeX file, and then I output the database in a 'longtabu' using \DTLforeach (from the 'datatool' package). I want to display one of the columns of the first row that appears after the page break in the header of the table on that new page.

But I can't figure how to code LaTeX to identify which row appears directly after the page break. I tried using \IfEq (in 'xstring') and \thepage to check if the previous page does not equal the current page, but within the 'longtable'/'longtabu' environment the page number is always the same as the page number that the table starts on. That is, it only knows the page that the table starts on; it doesn't know the page number for each individual row.

And then I tried looking at the commands/macros in the 'longtable' package to see if I could redefine the page breaking command to record the row number before or after the break, but I couldn't figure it out.

I also searched around for other solutions but haven't had any luck.

Any help? MWE attached.

In the MWE, I create the database in the TeX file. In reality, I pull from a CSV file using \DTLloaddb, but I don't think that makes any practical difference.

I use XeLaTeX to typeset, running on Mac OSX in case that matters.
Attachments
longtabumwe.pdf
MWE Output
(4.81 KiB) Downloaded 384 times
longtabumwe.tex
MWE TeX file
(2.34 KiB) Downloaded 432 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

tabu | Dynamic long Table Headings

Post by cgnieder »

GerlofVito wrote:I want to display one of the columns of the first row that appears after the page break in the header of the table on that new page.
I can't follow can you maybe explain with an example what exactly you're trying to achieve? In the case of your MWE: do you want »I want this to be the category of the row that follows on this page« to be replaced with »category 2«?

Regards
site moderator & package author
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

tabu | Dynamic long Table Headings

Post by cgnieder »

After looking into longtable.sty I doubt that dynamic headers can be done easily. The head is stored in a box once and then reinserted every time it is needed. I believe one would have to rewrite some parts of longtable...
site moderator & package author
GerlofVito
Posts: 27
Joined: Wed May 16, 2012 8:24 pm

tabu | Dynamic long Table Headings

Post by GerlofVito »

do you want »I want this to be the category of the row that follows on this page« to be replaced with »category 2«
Yes, exactly. In the case of the MWE, I want the header on the second page to say "category 2".
The head is stored in a box once and then reinserted every time it is needed.
So this table is not going to span three pages. At most, it will start on one and continue on to the next.

Would it be possible to redefine the command that creates the header on subsequent pages (\endhead) to save the row number where the break occurs? (Whether it's the row number before or after the break doesn't matter, since I can calculate the row number that I want from either.) Or to redefine another command (like the page break command) to store a variable like the category itself or the row number (which I can then use to get the category)? Or is 'longtable' totally unaware of the contents of the rows when it decides to make the page break?

Thanks for any help/ideas.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

tabu | Dynamic long Table Headings

Post by cgnieder »

The main problem here is that all heads are stored before the table is typeset. You would need to know the specific row number at the beginning of the table.

After trying out a few things that all failed I'm out of ideas right now. Maybe someone else will have an idea.

Regards
site moderator & package author
GerlofVito
Posts: 27
Joined: Wed May 16, 2012 8:24 pm

tabu | Dynamic long Table Headings

Post by GerlofVito »

The main problem here is that all heads are stored before the table is typeset.
I had an example that seemed to be setting a variable in the header with information after the body, but I've overwritten it since then and can't reproduce it now. So ... not sure if/how I managed that.

Thanks for your help. I'll wait and see if anyone else has ideas and figure out a workaround in the meantime.
Post Reply