1

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!

  • (i) long table should not be enclosed in table environment, (ii) longtable (as well longtabu) have special syntax for repeating column headers and footers on each page, which (so far) are not part of your command and are superfluous at tables shorter than one page (it is described in these package documentation) , (iii) frankly said, i don't see any benefits in table design using your command \dissertationTable, i would rather stick with standard approach at writing of tables. – Zarko Feb 8 at 3:22
  • Zarko, I agree; the command I included was by way of showing the kind of thing I'm after as a MWE, not a suggestion that I want to have a special command. I have thus far failed at figuring out the correct syntax for the longtable to get it to work spanning multiple pages, but I think longtable or longtabu would be the ideal solution if I could get it to work. That being said, I would also like to know if there is a way to detect a page break in TeX or LaTeX as that would be a useful thing to know for a horde of other things I'm likely to come across in the future. – Jason Feb 8 at 3:27
  • as examples of the use longtable and ltablex packages see tex.stackexchange.com/questions/392512, tex.stackexchange.com/questions/368444. ˙longtabu` is based on longtable so the specific syntax for long tables are the same. for details read documentations for those packages. beside mentioned packages for long table exist many others (supertabular etc). – Zarko Feb 8 at 3:36
2

an example of using longtabu table with repeated headers and footers:

\documentclass[11pt]{book}
\usepackage[a4paper,showframe]{geometry}
\usepackage{longtable, tabu}
    \tabulinesep = ^2mm_2mm
\usepackage[skip=1ex]{caption}

\usepackage{lipsum}

\begin{document}

\begin{longtabu} to \linewidth { l X[1,l] X[1,l]}
    \caption{Some table}
\label{tablere}                             \\
    \tabucline [1pt] -
These & Are & Headings                      \\
    \tabucline -
\endfirsthead
%---------------------------------------------------------------%
    \caption{Some table \hfill(continued)}            \\
    \tabucline [1pt]-
These & Are & Headings                      \\
    \tabucline -
\endhead
%---------------------------------------------------------------%
\multicolumn{3}{r}{\footnotesize\textit{continued on the next page}}
\endfoot
    \tabucline [1pt]-
\endlastfoot
%---------------------------------------------------------------%
% table body
    \everyrow{\tabucline - }
first row   & \lipsum*[2]    & \lipsum*[2]  \\
%    \midrule
second row  & \lipsum*[13]   & \lipsum*[13] \\
%    \midrule
third row  & \lipsum*[23]   & \lipsum*[23]  \\
%    \midrule
forth row   & \lipsum*[32]   & \lipsum*[32] \\
%    \midrule
fifth row   & \lipsum*[42]   & \lipsum*[43] \\
\end{longtabu}

\end{document}

note:

  • for the final form of the table, the document must be compiled at least twice
  • tables used longtable and longtabu (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 tables
  • (edit) for use of longtabe from package tabu you should be aware, that this package is still broken. see @Ulrike Fischer comment below answer.
  • tabularx is intended for (short) tables (usually enclosed in table float environment), which can be fit on one page
  • tabularx can be extend to long table by use of the package ltablex:

    \documentclass[11pt]{book}
    \usepackage[a4paper,showframe]{geometry}
    \usepackage{booktabs,ltablex}    % <---
        \keepXColumns
    \usepackage[skip=1ex]{caption}
    
    \usepackage{lipsum}
    
    \begin{document}
    
    \begin{tabularx}{\linewidth}{ l X X}
        \caption{Some table}
    \label{tablere}                             \\
        \toprule
    These & Are & Headings                      \\
        \midrule
    \endfirsthead
    %---------------------------------------------------------------%
        \caption{Some table \hfill(continued)}            \\
        \toprule
    These & Are & Headings                      \\
        \midrule
    \endhead
    %---------------------------------------------------------------%
    \multicolumn{3}{r}{\footnotesize\textit{continued on the next page}}
    \endfoot
        \bottomrule
    \endlastfoot
    %---------------------------------------------------------------%
    % table body
    first row   & \lipsum*[2]    & \lipsum*[2]  \\
        \midrule
    second row  & \lipsum*[13]   & \lipsum*[13] \\
        \midrule
    third row  & \lipsum*[23]   & \lipsum*[23]  \\
        \midrule
    forth row   & \lipsum*[32]   & \lipsum*[32] \\
        \midrule
    fifth row   & \lipsum*[42]   & \lipsum*[43] \\
    \end{tabularx}
    
    \end{document}
    

result is similar as before. for more details about settings long tables read documentation of packages which you use.

  • tabu is currently broken in various places. See the issue list at github.com/tabu-fixed/tabu. I would recommend not to use it. – Ulrike Fischer Feb 8 at 7:44
  • @UlrikeFischer, recently version (2.10) has added some bug fixes (thanks to David), so it works now better than original version (2.8). i know that it still contains bugs, but in most cases it works sufficiently reliably. i will add one another solution with use of ltablex asap. – Zarko Feb 8 at 9:41
  • @zarko 2.10 is not released see also David's comment at github.com/tabu-fixed/tabu/issues/1 – albert Feb 8 at 10:11
  • @albert, how than i have it? i only update my MikTeX installation ... i'm aware that it still not have (officially) new maintainer). if you will check my previous answers regarding tabu you will see, that i newer recommend to use tabu and always warn op at its use. so in my answer i only show, how to define column headers at longtabu (as well at ltablex version of long tables) and not recommend to use it. anyway, thank you for your concern. – Zarko Feb 8 at 10:29
  • 1
    @Zarko I know that some of the bugs has been fixed - one of them is actually from me - but I also know that some more are lurking in the code, I saw e.g. questions about it in a german group, and it will take weeks or month to sort them out as neither David nor me nor other from the team have much time to look into it and the maintainer doesn't do it, so better add to every answer with tabu a very large warning. – Ulrike Fischer Feb 8 at 11:07

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.