I have a large number of tables (several dozen) which contain either amino acid or DNA nucleotide sequences, and are produced by a semi-automated bioinformatics workflow.
These tables are fairly long, often running to two or even three pages, therefore I need to use a table-making environment that supports a multi-page typesetting capability. I decided to use the xtab package, based upon advice I found in section 3.4.2 of this document at tug.org:
The xtab package has functions very similar to those of supertabular but it corrects some defects thus it is recommended.
One of the nice features that xtab offers is a capability to print a table header that will appear at the top of each subsequent page after the first one. However, when xtab creates a page break in the vicinity of a midline rule, it seems to prefer always placing the page break immediately before the midrule, so that the midrule appears at the top of the next page, instead of at the bottom of the previous one. While this may look good when the multi-page table header feature is disabled, it looks wrong when multi-page headers are operational.
Below, I've included a MWE, and a screenshot of the output that it produces when I compile with xelatex:
% Basic document setup
\documentclass[11pt]{article}
\usepackage[margin=1in]{geometry}
\geometry{letterpaper}
\usepackage{fontspec}
\setmainfont{Tinos}
% Table-specific setup
\usepackage{xtab} % Needed for multi-page tables
\usepackage{multirow} % Needed because some cells span 2 rows
\usepackage{booktabs} % Improves appearance of horizontal lines and rules
\newcommand{\otoprule }{\midrule[\heavyrulewidth]}
\usepackage{seqsplit} % Needed for line breaking amino acid sequences
\usepackage{siunitx} % Needed for aligning numbers in columns
\sisetup{
table-format = 2.2
}
\begin{document}
\begin{center}
% Print this header at the top of the first page. Enclose 3rd column in
% brackets as a workaround to a weird bug that seems to arise from an
% interaction between xtab and siunitx packages.
\tablefirsthead{\toprule
Name & Type & {ID Number} & Amino Acid Sequences \\
\otoprule}
% Print this header at the top of all subsequent pages -- I made it identical
% to above, but in principle it could be different
\tablehead{\toprule
Name & Type & {ID Number} & Amino Acid Sequences \\
\otoprule}
% Begin actual table body
\begin{xtabular}{lcS[table-number-alignment = right]p{0.6\textwidth}}
\multirow[t]{2}{*}{ABCD1001} & A & 1 & \seqsplit{CVPCYFWIIQMADNYCCYFMSRMCRPVFMTGHKWWANNQCVERSVTHKDFGRANAAFAKAYTGRNYHCNYKRYWYNNATQYPHMAEWHT} \\
\cmidrule(l){2-4}
& B & 2 & \seqsplit{AAWLYALGCQTDVYDISKYIQCGLEYRIGPCQRPGGWGYYFFHFFDVWTIDSAPDISVIKDRKKCMEQTADTISHVGLGTESTPKQIIAALLGDYGFLGCYNEL} \\
\midrule
\multirow[t]{2}{*}{ABCD1002} & A & 3 & \seqsplit{VMKCDPLWSDLFWTFNRMVKKKCDCARILFEVRVWISCQLMVSYLNWSIILEIRLIGEFSHGQQIWRLFNTKTDRWMVDEDGDNHFQRKVICFFNVRQDMPPNLFFTVWNDWMHTQTDH} \\
\cmidrule(l){2-4}
& B & 4 & \seqsplit{FRTWPHLAQESTRSITTLPRRISFMFCYDQYNEMRPACVICSDMVAYYILAPGKGAFTCEWVGRAVMNHHEHDMQMGEAIHRQEIYVHKDWDAI} \\
\midrule
\multirow[t]{2}{*}{ABCD1003} & A & 5 & \seqsplit{SIDYDEESNMPHDPQEEWWNTLPHQKYPLGCGQEDPWDYKNNIFRAYAWIYEWNHVKHDKTAIHTHVVKQAHCPNRHFFGFLCNLSQELMNSF} \\
\cmidrule(l){2-4}
& B & 6 & \seqsplit{EEDRYNFYVNWIADRFLVCKPEFWDAFLYKKLWCFATNSKAFGETDCYKDAWYYFIHPEEKMSDQATWEAGIMNWLQEQTMVQQQTDCISA} \\
\midrule
\multirow[t]{2}{*}{ABCD1004} & A & 7 & \seqsplit{AYRIGEDGRFRQGRDKINKYDRATHFLQYHGRTVWRWHQYEKVYTFIMAYVPGFQYCPDGVPYVNSRAKYHKGVWCCDIQWVQEACEWSGFCLNARTCACCRHRGSDVVQASK} \\
\cmidrule(l){2-4}
& B & 8 & \seqsplit{NGLGSNQQVVSVGMNMLCFFKPFFGHNAGGYDVQAVHVWSDLDIHTDGDWHNNSCMTSIVDAPQTPHLMWNAPKWNIAWPVPPVNGYTIFKPHSKTIMAKNVEGEQECVHFKNQA} \\
\midrule
\multirow[t]{2}{*}{ABCD1005} & A & 9 & \seqsplit{FNFHFPQDPYHGEGTGPDDVMWKEKSLPTPIWVLWKIEYNVVAHCLRGSPNYNNADRGDCCHAFQNHKEIWQDAITIFENGWCSCIDKCAQSVDIPIDHQEQCNKMQHCDAAME} \\
\cmidrule(l){2-4}
& B & 10 & \seqsplit{CCIYPFWIACCHCFELTAEQFSFCYGVQHVYHPEYSDKLCNNQFFSSILNRHYIPYAAGGWEQAMVVCKLFQPVMVKKWNTDFSHADCR} \\
\midrule
\multirow[t]{2}{*}{ABCD1006} & A & 11 & \seqsplit{KPIPQESQYAWLVNLVTMCCAGRAWSLAERMHFYCQMSSIGAHPGHVRGGRWEAEIIQNHGENLHRTDRVAFKMTYPTKFCRYVITQFMMQQWLQHNPYQGMIMHIIVGVRSNTILE} \\
% Uncommenting the line below results in a xelatex compilation error
% \nopagebreak
\cmidrule(l){2-4}
& B & 12 & \seqsplit{IWCTCISSPDKWWEDPKLYSYNWHKVAIMLGYFASVMFCIYQSCYIIAMLRMNPFRCWNSWVDVCIIQGYGCSKKQDVKDFEHLQYGNFIETVR} \\
\midrule
\multirow[t]{2}{*}{ABCD1007} & A & 13 & \seqsplit{NDAEWKGALINLVGMESQWKNRHGDYYGYAGRVYIPCNAQFVCWCNDLHEMVYNTMGPPCIPHMGISERSWFSCQNDVHRYGPAHVDRSVCVRFMEHVDHSVMKLVPHELTSSGI} \\
\cmidrule(l){2-4}
& B & 14 & \seqsplit{YHQQACAYPSYRFTSWNCEDAKYEKKIQWVAKTQFFGWPTPFMSDNPGEQDSKTLMFIRMPYPGEYFNQNRQNSGQLQRDQYGRWNCQKDYYMQNCFCT} \\
\bottomrule
\end{xtabular}
\end{center}
\end{document}
Ideally, I'd like to simply suppress page breaks systematically before all midline rules (thereby forcing the break to take place immediately after the next midline rule), however, when I actually tried this inside of xtab using the \nopagebreak command, it resulted in an error message.
My question: What other penalization techniques can I use inside of xtab, besides \nopagebreak, to force line breaks to always occur after a midline rule instead of before?
Also, before answering, please note that a highly specific inverse solution, in which I force a line break to take place at a very particular location, is not desirable. As I said at the beginning, I have dozens of tables to contend with, and I'd still like xelatex to do most of my thinking for me--I don't want to have to make fussy hand corrections to dozens of tables; rather I'd just like to influence the page break-related scoring system a bit, at a fairly high level. It occurs to me, for example, that a good solution might be to simply redefine the \midrule and \cmidrule commands from booktabs so that these commands themselves somehow tell xelatex that they prefer to be page-broken after they are printed rather than before. However, I have no idea how one would actually go about doing something like this.


longtablepackage yet, nor other options such assupertabular. If someone with more experience than me were able to suggest a fix which substitutes one of these alternative options in place of thextabpackage, I would gladly consider it. However, thextabis already very close to producing the output that I want, so I was hoping someone who understands TeX's pagebreak scoring system might see this, and be able to suggest a trivial tweak. – stachyra Oct 24 '19 at 16:16longtablepackage does seem to be a viable alternative that fixes the issue. Nevertheless, I still think it would be instructive to see how this could have been solved usingxtabinstead, as I had initially anticipated when I posed the question. – stachyra Oct 24 '19 at 17:44