I am trying to write a latex template for math dissertations for my university and I have gotten most of the formating built into the appropriate class file. However, one issue that I'm not sure how to solve is their requirements for tables. They need to be full-text-width (which I achieve fine with using tabularx environment), have dedicated headers (which is easy enough), and have a title/label (again, not too difficult). The part I'm having trouble with is the following: If the table extends to be past the current page, it should be split and continued on the next page with a reference to the table's title with "continued" appended, the headers need to be restated, and then the table continued. So far the following is my general idea of structuring a macro:
\documentclass{article}
\usepackage{tabularx}
\newcommand{\dissertationTable}[5]{
\begin{table}
\centering
\caption{#4}
\begin{tabularx}{\textwidth}{#1}
#2\\ \hline% This is the header line
#3\\ \hline% This is the body of the table,
% which should include all the relevant line breaks etc.
\end{tabularx}
\label{#5}
\end{table}
}
\begin{document}
\dissertationTable{lXX}{These & Are & Headings}{These are & some rows& to see\\ how it & works & and to\\ demonstrate & how to & enter info.}{Some Table}{tableref}
\end{document}
The above works decently well to make a table, and I could reuse the #2
argument to reprint the heading if I could detect a pagebreak, and use the label in the #5
argument to cite the name (or just use the #4 caption directly) and append "continue". But I am not sure how to detect the pagebreak automatically. I also have issues trying to get the entire header in bold text and none of the content in bold text; the alignment tabs seem to break the scope of the \bfseries
command.
I looked into this more generally and saw the longtable
package and/or the tabu
package, but I can't seem to figure out the syntax correctly to get what I'm after. I'm pretty sure the tabu
package is capable of doing most/everything I want and I'm probably just being dumb, but I can't get it to compile more than a basic table without errors so I'm doing something stupid.
Regardless of whether one uses tabu or some clever macro, my goal is to generate some kind of command or environment that hides as much off the require formatting as possible (most of the students using this template will have very minimal TeX understanding, so the less they need to know the better). Ideally I'd use something that detects the number of align characters and allows me to set the left/right align characters within the command itself, instead of requiring it of the student (eg the first argument; {lXX}
, in the MWE above).
Thus, if someone could either help me out with the syntax with longtable/tabu or explain how to detect a page break to make such a command myself, I'd very much appreciate it. And if there is a nice way to preformat the table for the alignment of each column without knowing how many columns there will be, that would be the cherry on top.
Thanks!
Best Answer
an example of using
longtabu
table with repeated headers and footers:note:
longtable
andlongtabu
(as well others) can break between pages only between rows and not inside them. consequently at long cells' contents can arose empty spaces below some parts of tableslongtabe
from packagetabu
you should be aware, that this package is still broken. see @Ulrike Fischer comment below answer.tabularx
is intended for (short) tables (usually enclosed intable
float environment), which can be fit on one pagetabularx
can be extend to long table by use of the packageltablex
:result is similar as before. for more details about settings long tables read documentation of packages which you use.