| 1 |
% \iffalse (meta-comment) |
| 2 |
% ----------------------------------------------------------------- |
| 3 |
% booktabs.dtx |
| 4 |
% Copyright (C) 1995--2020 Simon Fear |
| 5 |
% Maintained by Danie Els <[email protected]> |
| 6 |
% |
| 7 |
% This file is part of the booktabs package for publication |
| 8 |
% quality tables for LaTeX |
| 9 |
% ----------------------------------------------------------------- |
| 10 |
% |
| 11 |
% This work may be distributed and/or modified under the conditions |
| 12 |
% of the LaTeX Project Public License, either version 1.3c of this |
| 13 |
% license or (at your option) any later version. The latest version |
| 14 |
% of this license is in |
| 15 |
% http://www.latex-project.org/lppl.txt |
| 16 |
% and version 1.3c or later is part of all distributions of LaTeX |
| 17 |
% version 2008/05/04 or later. |
| 18 |
% |
| 19 |
% ----------------------------------------------------------------- |
| 20 |
% \fi |
| 21 |
% |
| 22 |
% \iffalse |
| 23 |
%<*driver> |
| 24 |
\ProvidesFile{booktabs.dtx} |
| 25 |
%</driver> |
| 26 |
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] |
| 27 |
%<package>\ProvidesPackage{booktabs} |
| 28 |
%<*package> |
| 29 |
[2020/01/12 v1.61803398 Publication quality tables] |
| 30 |
%</package> |
| 31 |
% |
| 32 |
%<*driver> |
| 33 |
\documentclass{ltxdoc} |
| 34 |
\usepackage{booktabs}[2020/01/12] |
| 35 |
\EnableCrossrefs |
| 36 |
\CodelineIndex |
| 37 |
\RecordChanges |
| 38 |
\setlength\hfuzz{15pt} |
| 39 |
\hbadness=7000 |
| 40 |
\MakeShortVerb{\=} |
| 41 |
\MakeShortVerb{\"} |
| 42 |
\begin{document} |
| 43 |
\DocInput{booktabs.dtx} |
| 44 |
\PrintChanges |
| 45 |
\PrintIndex |
| 46 |
\end{document} |
| 47 |
%</driver> |
| 48 |
% \fi |
| 49 |
% |
| 50 |
% \CheckSum{489} |
| 51 |
% \CharacterTable |
| 52 |
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 53 |
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 54 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 55 |
% Exclamation \! Double quote \" Hash (number) \# |
| 56 |
% Dollar \$ Percent \% Ampersand \& |
| 57 |
% Acute accent \' Left paren \( Right paren \) |
| 58 |
% Asterisk \* Plus \+ Comma \, |
| 59 |
% Minus \- Point \. Solidus \/ |
| 60 |
% Colon \: Semicolon \; Less than \< |
| 61 |
% Equals \= Greater than \> Question mark \? |
| 62 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 63 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 64 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 65 |
% Right brace \} Tilde \~} |
| 66 |
% |
| 67 |
% |
| 68 |
% |
| 69 |
% \DeleteShortVerb{\|} |
| 70 |
% \GetFileInfo{booktabs.dtx} |
| 71 |
% |
| 72 |
% \title{Publication quality tables in \LaTeX% |
| 73 |
% \thanks{This file has version number \fileversion, |
| 74 |
% (converging to phi, the golden ratio), |
| 75 |
% last revised \filedate.}} |
| 76 |
% \author{Simon Fear\\300A route de Meyrin\\Meyrin\\Switzerland} |
| 77 |
% \date{Printed \today} |
| 78 |
% |
| 79 |
% \maketitle |
| 80 |
% |
| 81 |
% |
| 82 |
% \begin{abstract} |
| 83 |
% This article describes some additional commands to enhance |
| 84 |
% the quality of tables in \LaTeX. Guidelines are given as |
| 85 |
% to what constitutes a good table in this context. The 2000 |
| 86 |
% release (Version 1.61) of the =booktabs= package, described |
| 87 |
% herein, adds some enhancements to the 1995 release (Version 1.00), |
| 88 |
% most notably =longtable= compatibility. |
| 89 |
% |
| 90 |
% Releases (Versions 1.618, 1.6180, 1.61803 and 1.618033) are |
| 91 |
% only bug patches, support for the =colortbl= package and better |
| 92 |
% compatability with =longtable=.\footnote{By Danie Els |
| 93 |
% (\texttt{[email protected]}) in the absence of the author.} |
| 94 |
% \end{abstract} |
| 95 |
% |
| 96 |
% \bigskip |
| 97 |
% |
| 98 |
% \section{Introduction} |
| 99 |
% |
| 100 |
% The routines described below are to enable the easy production |
| 101 |
% of tables such as should appear in published scientific books and |
| 102 |
% journals. What distinguishes these from plain |
| 103 |
% \LaTeX{} tables is the default use of additional space above and below rules, |
| 104 |
% and rules of varying `thickness'. What further distinguishes them from |
| 105 |
% the tables many people {\em do} produce using \LaTeX{} is the |
| 106 |
% absence of vertical rules and double rules. |
| 107 |
% |
| 108 |
% I must draw a clear |
| 109 |
% distinction between what I call here a {\em formal table}, |
| 110 |
% which is a set of values in labelled columns, as distinct from |
| 111 |
% what I will call a {\em tableau}. The latter is the kind of thing |
| 112 |
% illustrated in the \LaTeX{} manual, and increasingly |
| 113 |
% common as the output of |
| 114 |
% many database management systems; it will probably have |
| 115 |
% icons in abundance, and no doubt use colour too. |
| 116 |
% The layout of such a {\em tableau} is determined |
| 117 |
% (hopefully) as a one-off, given a jumble of material the |
| 118 |
% designer is trying to combine into a meaningful configuration. |
| 119 |
% But the layout of a {\em table} has been established over |
| 120 |
% centuries of experience and should only be altered in |
| 121 |
% extraordinary circumstances. |
| 122 |
% |
| 123 |
% By way of illustration, consider this tableau from the \LaTeX{} |
| 124 |
% manual (p. 64 old edition): |
| 125 |
% |
| 126 |
% \begin{center} |
| 127 |
% \begin{tabular}{||l|lr||} \hline |
| 128 |
% gnats & gram & \$13.65 \\ \cline{2-3} |
| 129 |
% & each & .01 \\ \hline |
| 130 |
% gnu & stuffed & 92.50 \\ \cline{1-1} \cline{3-3} |
| 131 |
% emu & & 33.33 \\ \hline |
| 132 |
% armadillo & frozen & 8.99 \\ \hline |
| 133 |
% \end{tabular} |
| 134 |
% \end{center} |
| 135 |
% |
| 136 |
% This is a hotch-potch of information that is probably |
| 137 |
% reasonably clearly presented as is (but is the emu stuffed or |
| 138 |
% not?). However, as a published table, this should |
| 139 |
% much rather appear along the lines suggested |
| 140 |
% further down the page in the manual: |
| 141 |
% |
| 142 |
% \begin{center} |
| 143 |
% \begin{tabular}{@{}llr@{}} \toprule |
| 144 |
% \multicolumn{2}{c}{Item} \\ \cmidrule(r){1-2} |
| 145 |
% Animal & Description & Price (\$)\\ \midrule |
| 146 |
% Gnat & per gram & 13.65 \\ |
| 147 |
% & each & 0.01 \\ |
| 148 |
% Gnu & stuffed & 92.50 \\ |
| 149 |
% Emu & stuffed & 33.33 \\ |
| 150 |
% Armadillo & frozen & 8.99 \\ \bottomrule |
| 151 |
% \end{tabular} |
| 152 |
% \end{center} |
| 153 |
% |
| 154 |
% It takes much less work to lay |
| 155 |
% this out, as a formal table; we don't have to work out a new |
| 156 |
% layout for everything we do. Moreover, we can be almost certain |
| 157 |
% that the data cannot be misread, because the reader does not |
| 158 |
% have to learn how to read some novel presentation. |
| 159 |
% |
| 160 |
% The above table cannot be produced in pure \LaTeX, |
| 161 |
% unfortunately. It can be laid out as it should be, but despite |
| 162 |
% your best efforts, using plain =\hline= commands produces |
| 163 |
% |
| 164 |
% \begin{center} |
| 165 |
% \begin{tabular}{@{}llr@{}} \hline |
| 166 |
% \multicolumn{2}{c}{Item} \\ \cline{1-2} |
| 167 |
% Animal & Description & Price (\$)\\ \hline |
| 168 |
% Gnat & per gram & 13.65 \\ |
| 169 |
% & each & 0.01 \\ |
| 170 |
% Gnu & stuffed & 92.50 \\ |
| 171 |
% Emu & stuffed & 33.33 \\ |
| 172 |
% Armadillo & frozen & 8.99 \\ \hline |
| 173 |
% \end{tabular} |
| 174 |
% \end{center} |
| 175 |
% |
| 176 |
% Note (if it is not already obvious) that there is not enough |
| 177 |
% space between the top line and the capital I of `Item', and so |
| 178 |
% on for all the lines: contrast with the previous version. Also, in |
| 179 |
% the first version |
| 180 |
% the top and bottom rules (ie lines) are |
| 181 |
% heavier than the middle rule, which is turn heavier than the |
| 182 |
% subrule underneath `Item'. Of course you \emph{could} redefine |
| 183 |
% =\doublerulesep= and then use =\hline\hline= to get something |
| 184 |
% near the same effect, and you could use struts to improve |
| 185 |
% the spacing. But you should not have to |
| 186 |
% think of such things. The =booktabs= style defines its commands so |
| 187 |
% that such things are taken care of automatically. |
| 188 |
% |
| 189 |
% In general, I would say that |
| 190 |
% this package is of no interest to those looking for |
| 191 |
% an alternative to Pic\TeX{} to conjure up fancy tableaux. |
| 192 |
% Rather, it is a style guide for authors of scientific papers |
| 193 |
% and books as regards table layout. It is not going too far to |
| 194 |
% say that if you cannot |
| 195 |
% create a table using the commands in this package, you should |
| 196 |
% redesign it. |
| 197 |
% |
| 198 |
% \subsection{A note on terminology\label{notation}} |
| 199 |
% |
| 200 |
% In British typesetting, a `line' is always called a `rule'. Perhaps |
| 201 |
% confusingly (for historic reasons in fact), the `thickness' of |
| 202 |
% rule is often referred to as is its `width' (whereas just about |
| 203 |
% everyone else would call this `depth' or `height', if they were thinking |
| 204 |
% of a horizontal rule). A `thick black line' is called a `heavy |
| 205 |
% rule'. I have used this terminology in most of the new commands |
| 206 |
% below. If nothing else it avoids confusion with =\hline=. |
| 207 |
% |
| 208 |
% \section{The layout of formal tables} |
| 209 |
% |
| 210 |
% You will not go far wrong if you remember two simple |
| 211 |
% guidelines at all times: |
| 212 |
% \begin{enumerate} |
| 213 |
% \item Never, ever use vertical rules. |
| 214 |
% \item Never use double rules. |
| 215 |
% \end{enumerate} |
| 216 |
% These guidelines may seem extreme but I have |
| 217 |
% never found a good argument in favour of breaking them. For |
| 218 |
% example, if you feel that the information in the left half of |
| 219 |
% a table is so different from that on the right that it needs |
| 220 |
% to be separated by a vertical line, then you should use two |
| 221 |
% tables instead. Not everyone follows the second guideline: |
| 222 |
% I have worked for a publisher who insisted on a |
| 223 |
% double light rule above a row of totals. But this would not |
| 224 |
% have been my choice. |
| 225 |
% |
| 226 |
% There are three further guidelines worth mentioning here as they |
| 227 |
% are generally not known outside the circle of professional |
| 228 |
% typesetters and subeditors: |
| 229 |
% \begin{enumerate}\setcounter{enumi}{2} |
| 230 |
% \item Put the units in the column heading (not in the body of |
| 231 |
% the table). |
| 232 |
% \item Always precede a decimal point by a digit; thus 0.1 |
| 233 |
% {\em not} just .1. |
| 234 |
% \item Do not use `ditto' signs or any other such convention to |
| 235 |
% repeat a previous value. In many circumstances a blank |
| 236 |
% will serve just as well. If it won't, then repeat the value. |
| 237 |
% \end{enumerate} |
| 238 |
% |
| 239 |
% Whether or not you wish to follow the minor niceties, |
| 240 |
% if you use only the following commands in your formal tables |
| 241 |
% your reader will be grateful. I stress that |
| 242 |
% the guidelines are not just to |
| 243 |
% keep the pedantic happy. The principal is that enforced structure of |
| 244 |
% presentation |
| 245 |
% enforces structured thought in the first instance. |
| 246 |
% |
| 247 |
% \section{Use of the new commands} |
| 248 |
% |
| 249 |
% \DescribeMacro\toprule |
| 250 |
% \DescribeMacro\midrule |
| 251 |
% \DescribeMacro\bottomrule |
| 252 |
% In the simplest of cases a table begins with a =\toprule=, has |
| 253 |
% a single row of column headings, then a dividing rule called |
| 254 |
% here a =\midrule=; after the columns of data we finish off with |
| 255 |
% a =\bottomrule=. Most book publishers set the =\toprule= and |
| 256 |
% =\bottomrule= heavier (ie thicker, or darker; see section \ref{notation}) |
| 257 |
% than the intermediate =\midrule=. However, when tables appear |
| 258 |
% in very small typesizes it is sometimes impossible to make this |
| 259 |
% distinction, and moreover quite a few journals routinely use all rules of |
| 260 |
% the same heaviness. |
| 261 |
% |
| 262 |
% The rule commands here all take a default |
| 263 |
% which may be reset within the document (preferably, but not |
| 264 |
% necessarily, in the preamble). For the top and bottom rules this |
| 265 |
% default |
| 266 |
% is =\heavyrulewidth= and for midrules it is =\lightrulewidth= |
| 267 |
% (fully described below). In very rare cases where you need to do |
| 268 |
% something special, you may use the optional arguments to the rule |
| 269 |
% commands which have formal syntax as follows: |
| 270 |
% \begin{quote} |
| 271 |
% "\toprule["\meta{wd}"]" \\ |
| 272 |
% "\midrule["\meta{wd}"]" \\ |
| 273 |
% "\bottomrule["\meta{wd}"]" |
| 274 |
% \end{quote} |
| 275 |
% where \meta{wd} is a \TeX dimension (for example 1pt, .5em, |
| 276 |
% etc.). |
| 277 |
% |
| 278 |
% All the rule commands described here go after the closing |
| 279 |
% =\\= of the preceding row (except =\toprule=, which |
| 280 |
% comes right after the =\tabular{}= command); in other words, |
| 281 |
% exactly where plain \LaTeX{} allows =\hline= or =\cline=. |
| 282 |
% |
| 283 |
% \DescribeMacro\cmidrule |
| 284 |
% Frequently we need a sub-rule to extend over only some of the columns, |
| 285 |
% for which we need a =\cmidrule= (the analogue of \LaTeX's =\cline= |
| 286 |
% command). Generally, this rule should not come to the full width of |
| 287 |
% the columns, and this is especially the case when we need to begin |
| 288 |
% a =\cmidrule= straight after the end of another one (\LaTeX's |
| 289 |
% =\cline=s crash into each other here if you are not extra careful with |
| 290 |
% =\extracolsep=). Thus, you will generally want to use the optional |
| 291 |
% `trimming' commands. |
| 292 |
% |
| 293 |
% The trimming commands, if used at all, go in |
| 294 |
% parentheses (like this), with no spaces separating them. The possible |
| 295 |
% specifications are =r=, =r{=\meta{wd}=}=, =l= and |
| 296 |
% =l{=\meta{wd}=}=, or any combination of these, where \meta{wd} is a |
| 297 |
% dimension, and =r= and =l= indicate whether the right and/or left ends |
| 298 |
% of the rule should be trimmed. The form without explicit argument is |
| 299 |
% equivalent to =r{\cmidrulekern}=, where =\cmidrulekern= defaults to |
| 300 |
% $0.5$ em, but can be set by the user in the preamble.\footnote{User |
| 301 |
% feedback suggested the Version 1.00 default, 0.25 em, was too |
| 302 |
% small. Sorry for any loss of backward compatibility. Remember that |
| 303 |
% you |
| 304 |
% can easily set \texttt{\textbackslash cmidrulekern} in the preamble, or just use |
| 305 |
% \texttt{(r\{.25em\})} to recover the original behaviour.} |
| 306 |
% |
| 307 |
% Here's an illustrative example: =(lr{.75em})= gives you a default |
| 308 |
% left trim and exactly $0.75$ em right trim. Equally valid here is |
| 309 |
% =(r{.75em}l)=.\footnote{As a matter of fact, \texttt{(lrrlr\{.75em\})} |
| 310 |
% does the same thing: only the |
| 311 |
% last encountered left and the last encountered right specification |
| 312 |
% are applied.} |
| 313 |
% |
| 314 |
% The full syntax of the command is |
| 315 |
% \begin{quote} |
| 316 |
% "\cmidrule["\meta{wd}"]("\meta{trim}"){"$a$--$b$"}" |
| 317 |
% \end{quote} |
| 318 |
% where \meta{wd} is an optional rule width command, in square |
| 319 |
% brackets [like this] (the |
| 320 |
% default here is =\cmidrulewidth=), and the last argument, \emph{which |
| 321 |
% is not optional}, gives the column numbers to be spanned. |
| 322 |
% |
| 323 |
% An example of the commands in use is given by the code used to |
| 324 |
% produce the example table above: |
| 325 |
% \begin{verbatim} |
| 326 |
% \begin{tabular}{@{}llr@{}} \toprule |
| 327 |
% \multicolumn{2}{c}{Item} \\ \cmidrule(r){1-2} |
| 328 |
% Animal & Description & Price (\$)\\ \midrule |
| 329 |
% Gnat & per gram & 13.65 \\ |
| 330 |
% & each & 0.01 \\ |
| 331 |
% Gnu & stuffed & 92.50 \\ |
| 332 |
% Emu & stuffed & 33.33 \\ |
| 333 |
% Armadillo & frozen & 8.99 \\ \bottomrule |
| 334 |
% \end{tabular} |
| 335 |
% \end{verbatim} |
| 336 |
% |
| 337 |
% \DescribeMacro\addlinespace |
| 338 |
% Occasionally we want to put an extra space between certain rows |
| 339 |
% of a table; for example, before the last row, if this is a |
| 340 |
% total. This is simply a matter of inserting |
| 341 |
% \begin{quote} |
| 342 |
% "\addlinespace["\meta{wd}"]" |
| 343 |
% \end{quote} |
| 344 |
% after the =\\= alignment marker. Between ordinary rows of text, the |
| 345 |
% effect is identical to the ordinary \LaTeX\ usage |
| 346 |
% =\\[\defaultaddspace]=, which I find rather clumsy, and it is better |
| 347 |
% than =\\ \\=, which inserts too much space. Also, |
| 348 |
% =\addlinespace= can be used before, after, or between rules if you |
| 349 |
% want to control the exact amount of space to be inserted. The default |
| 350 |
% space before or after an adjacent rule is replaced by exactly |
| 351 |
% =\defaultaddspace= or the amount of |
| 352 |
% space specified in the optional argument.\footnote{This is a change |
| 353 |
% from version 1.00, where the space was sometimes \emph{in addition |
| 354 |
% to} default rule space.} |
| 355 |
% |
| 356 |
% \section{Abuse of the new commands} |
| 357 |
% |
| 358 |
% Let's face it, nobody can leave well alone, so here are some |
| 359 |
% guidelines and extra commands. |
| 360 |
% |
| 361 |
% The new rule commands are not guaranteed to work with =\hline= |
| 362 |
% or =\cline=, although these remain available and unchanged. I |
| 363 |
% cannot foresee any reason to want to mix them. |
| 364 |
% |
| 365 |
% More importantly the rules generated by the new commands are in |
| 366 |
% no way guaranteed to connect with verticals generated by ={|}= |
| 367 |
% characters in the preamble. This is a feature (see above). You |
| 368 |
% should not use vertical rules in tables, end of story. |
| 369 |
% |
| 370 |
% \DescribeMacro\morecmidrules |
| 371 |
% If you just cannot stop yourself from using a double rule, |
| 372 |
% even a construction as bizarre as =\toprule\bottomrule\midrule= |
| 373 |
% will work without generating an error message (just as you can |
| 374 |
% double =\hline=). These rules will be separated by the ordinary |
| 375 |
% \LaTeX\ separator =\doublerulesep=. However if your perversion |
| 376 |
% is to want double =\cmidrule=s you will need the extra command |
| 377 |
% =\morecmidrules= to do so properly, because normally two |
| 378 |
% =\cmidrule=s in a row is a sane construction |
| 379 |
% calling for two rules on the same `rule row'. Thus in |
| 380 |
% \begin{quote} |
| 381 |
% "\cmidrule{1-2}\cmidrule{1-2}" |
| 382 |
% \end{quote} |
| 383 |
% the second command writes a rule that just overwrites the first |
| 384 |
% one; I suppose you wanted |
| 385 |
% \begin{quote} |
| 386 |
% "\cmidrule{1-2}\morecmidrules\cmidrule{1-2}" |
| 387 |
% \end{quote} |
| 388 |
% which gives you a double rule between columns one and two, |
| 389 |
% separated by =\cmidrulesep= (note: since a =\cmidrule= is |
| 390 |
% generally very light, the ordinary =\doublerulesep= is probably |
| 391 |
% too much space). Finish off a whole row of rules before giving the |
| 392 |
% =\morecmidrules= command. Note that =\morecmidrules= has no |
| 393 |
% effect whatsoever if it does not immediately follow a |
| 394 |
% =\cmidrule= (ie it is not a general space-generating command). |
| 395 |
% |
| 396 |
% \DescribeMacro\specialrule |
| 397 |
% If you find some extraordinary need to specify exactly $0.5$ em, say, between two |
| 398 |
% rules, you could use a construction such as =\midrule = |
| 399 |
% =\addlinespace[.5em] \midrule=. In a rare fit of tolerance, though, |
| 400 |
% I have also |
| 401 |
% provided the command |
| 402 |
% \begin{quote} |
| 403 |
% "\specialrule{"\meta{wd}"}{"\meta{abovespace}"}{"\meta{belowspace}"}" |
| 404 |
% \end{quote} |
| 405 |
% where all three arguments are mandatory (I couldn't be bothered to |
| 406 |
% program in defaults). If you use this frequently, you have |
| 407 |
% misunderstood the purpose and content of the guidelines given above. A |
| 408 |
% preceeding rule does not add its default space below, and a following |
| 409 |
% rule adds no space above itself, so you get \emph{exactly} the space |
| 410 |
% specified in the arguments.\footnote{This is a change from Version 1.00, |
| 411 |
% which rather liked to add an extra \texttt{\textbackslash doublerulesep} space whenever it |
| 412 |
% could.} |
| 413 |
% |
| 414 |
% |
| 415 |
% \section{Booktabs and longtables} |
| 416 |
% |
| 417 |
% If you have both =booktabs= and =longtable= packages loaded, the |
| 418 |
% =booktabs= rule commands can now all be used exactly as described |
| 419 |
% above, within a longtable. |
| 420 |
% |
| 421 |
% There is an addition worth noting: within a =longtable=, you can use |
| 422 |
% the optional left and right trimming commands, which normally only |
| 423 |
% work for =\cmidrule=s, with =\toprule=, =\midrule= and =\bottomrule= |
| 424 |
% (and if you must, also with =\specialrule=). Users who hacked the |
| 425 |
% previous release for longtable compatability\footnote{Jim Service was |
| 426 |
% the first} seemed to like all the rules to be right trimmed 0.5 em. I |
| 427 |
% think you can do the same by making =@{}= be the last column |
| 428 |
% specifier. Still, after working out the rest of the code, it was easy |
| 429 |
% to add parsing for the optional arguments, so I did. (I didn't go the |
| 430 |
% whole way and allow the optional trimming \emph{outside} a |
| 431 |
% =longtable=; this would be a huge amount of work. If you must have |
| 432 |
% trimmed rules, make all your tables be =longtable=s!) |
| 433 |
% |
| 434 |
% A somewhat technical note: within a =longtable=, =\hline= and |
| 435 |
% =\hline\hline= both produce a \emph{double} rule (to allow for page |
| 436 |
% breaks occurring at that point). But the =booktabs= rules do |
| 437 |
% \emph{not}. Longtable's automatic doubling of =\hline= is |
| 438 |
% questionable, even according to the documentation within that |
| 439 |
% package. But doubled =booktabs= rules make almost no sense at all. In |
| 440 |
% the unfortunate event that a =booktabs= rule should occur at a page |
| 441 |
% break, then you will have to make the necessary adjustments by |
| 442 |
% hand.\footnote{Fixed in version 1.618033 (Morten H{\o}gholm)} |
| 443 |
% (In general, this will mean deleting the offending rule.) |
| 444 |
% |
| 445 |
% |
| 446 |
% \section{Booktabs and and the colortbl package} |
| 447 |
% |
| 448 |
% =Booktabs= is now compatible with the =colortbl= package.\footnote{Since v1.6180} |
| 449 |
% The \cmd{\arrayrulecolor} command will result in coloured |
| 450 |
% rules if the =colortbl= package is loaded. |
| 451 |
% |
| 452 |
% |
| 453 |
% \section{Technical summary of commands} |
| 454 |
% |
| 455 |
% The new rule commands are valid inside the standard =tabular= (and |
| 456 |
% =array=) environment, in the modified =tabular= and =array= of |
| 457 |
% =\usepackage{array}=, and within both standard tables and longtables |
| 458 |
% after =\usepackage{longtable}=. |
| 459 |
% |
| 460 |
% The commands follow the standard placement syntax of =\hline=. |
| 461 |
% There can be space (including carriage-return, |
| 462 |
% but not two carriage-returns) between successive |
| 463 |
% rule commands.\footnote{A welcome change from Version 1.00, where space between |
| 464 |
% rule commands generated a very baffling error message.} |
| 465 |
% |
| 466 |
% In what amounts to quite a big change from former releases, within |
| 467 |
% the macro code I now define three classes of rules. (But we don't need these |
| 468 |
% definitions within ordinary use, so I haven't even mentioned them above.) |
| 469 |
% A class 1 rule (otherwise called a `normal' rule) is any of |
| 470 |
% =\toprule=, =\midrule=, =\bottomrule=, or =\cmidrule=. The class 2 |
| 471 |
% rules are =\specialrule= and =\addlinespace=. Finally, a class 0 rule |
| 472 |
% is none of the preceeding --- or in other words, not a rule at |
| 473 |
% all.\footnote{Except that \texttt{\textbackslash hline} and |
| 474 |
% \texttt{\textbackslash cline} are class 0. Still, there |
| 475 |
% is no reason to lose sleep over this, since one would not want to mix |
| 476 |
% the two rule-drawing systems.} Note that =\addlinespace= counts as a |
| 477 |
% class 2 rule, not as class 0 text. |
| 478 |
% |
| 479 |
% In the following, we first describe each command in `normal use', meaning |
| 480 |
% that the rule is being used between two lines of text (or more |
| 481 |
% technically, is preceded and followed by a class 0 rule). After that, |
| 482 |
% we will look at the exceptions. |
| 483 |
% \begin{quote} |
| 484 |
% "\toprule["\meta{wd}"]" |
| 485 |
% \end{quote} |
| 486 |
% A rule of width \meta{wd} (default =\heavyrulewidth=) with |
| 487 |
% =\abovetopsep= space above and |
| 488 |
% =\belowrulesep= extra vertical space inserted below it. By default, |
| 489 |
% =\abovetopsep= is zero, which seems sensible for a rule designed to |
| 490 |
% go at the top. However, if your |
| 491 |
% tables have captions, it can make sense to use =\abovetopsep= to |
| 492 |
% insert a reasonable amount of space between caption and table, |
| 493 |
% rather than remember to use a =\vspace{}= command in the float. |
| 494 |
% \begin{quote} |
| 495 |
% "\midrule["\meta{wd}"]" |
| 496 |
% \end{quote} |
| 497 |
% A \meta{wd} (default =\lightrulewidth=) rule with |
| 498 |
% =\aboverulesep= space above it and |
| 499 |
% with =\belowrulesep= space below it. |
| 500 |
% \begin{quote} |
| 501 |
% "\bottomrule["\meta{wd}"]" |
| 502 |
% \end{quote} |
| 503 |
% A \meta{wd} (default =\heavyrulewidth=) rule with =\aboverulesep= |
| 504 |
% space above it and with =\belowbottomsep= space below it. By default |
| 505 |
% =\belowbottomsep= is zero\footnote{This is a change from Version 1.00, |
| 506 |
% where there was always a \texttt{\textbackslash belowrulesep}}. |
| 507 |
% There is a frequent and legitimate reason |
| 508 |
% you might want space below a bottom rule: namely, when there's a table |
| 509 |
% footnote.\footnote{But don't use footnotes, Donald.} |
| 510 |
% If you don't override the default you could use |
| 511 |
% =\bottomrule \addlinespace[\belowrulesep]= |
| 512 |
% or you could put a suitably sized strut |
| 513 |
% into the footnote text.\footnote{I don't like either of these. Sort it out in |
| 514 |
% Version 1.618?} But the default has to be zero, so that it behaves |
| 515 |
% sensibly in a =longtable= footer. |
| 516 |
% \begin{quote} |
| 517 |
% "\cmidrule["\meta{wd}"]("\meta{trim}"){"$a$--$b$"}" |
| 518 |
% \end{quote} |
| 519 |
% A \meta{wd} (default =\cmidrulewidth=) rule with |
| 520 |
% =\aboverulesep= space above it (unless following another |
| 521 |
% =\cmidrule=, in which case it is on the same vertical alignment; or |
| 522 |
% if following =\morecmidrules=, separated from a previous =\cmidrule= |
| 523 |
% by =\cmidrulesep=). A =\cmidrule= has |
| 524 |
% =\belowrulesep= below it (unless followed by another |
| 525 |
% =\cmidrule=, in which case the following rule is on the same |
| 526 |
% vertical alignment; or if followed by =\morecmdirules=, when there |
| 527 |
% will be |
| 528 |
% =\cmidrulesep= below it). |
| 529 |
% |
| 530 |
% The =\cmidrule= spans columns $a$ to $b$ as specified in the mandatory |
| 531 |
% argument. The optional argument \meta{trim}, which goes in parentheses |
| 532 |
% if at all, can contain any sequence of the tokens =r=, =l= and |
| 533 |
% ={=\meta{wd}=}=, with the latter setting the kerning to be applied to |
| 534 |
% right or left sides as specified by the immediately preceding token. |
| 535 |
% (There's currently no error checking done here, so be careful to get |
| 536 |
% the syntax right.) |
| 537 |
% \begin{quote} |
| 538 |
% "\morecmidrules" |
| 539 |
% \end{quote} |
| 540 |
% Instructs \LaTeX\ to begin a new row of =\cmidrules=, |
| 541 |
% separated from the last by =\cmidrulesep=. Has no meaning |
| 542 |
% in any other context. |
| 543 |
% \begin{quote} |
| 544 |
% "\specialrule{"\meta{wd}"}{"\meta{abovespace}"}{"\meta{belowspace}"}" |
| 545 |
% \end{quote} |
| 546 |
% A \meta{wd} rule (note: here this is a mandatory argument) with |
| 547 |
% \meta{abovespace} above it and \meta{belowspace} below it. |
| 548 |
% \begin{quote} |
| 549 |
% "\addlinespace["\meta{wd}"]" |
| 550 |
% \end{quote} |
| 551 |
% Technically this has the same effect as |
| 552 |
% =\specialrule{0pt}{0pt}{=\meta{wd}=}=, i.e. a zero-width rule with no |
| 553 |
% space above and with \meta{wd} (default =\defaultaddspace=) space |
| 554 |
% below. This command was primarily designed to add space between rows |
| 555 |
% in the body of the table, but it may also be used to specify an exact |
| 556 |
% amount of space above or below a class 1 rule. |
| 557 |
% |
| 558 |
% \vspace{1em} |
| 559 |
% Now we come to the exceptions to the above. We have already seen in |
| 560 |
% the definitions that the type 2 rules are preceded and followed by |
| 561 |
% exactly the amount of space specified by the arguments. That is, a |
| 562 |
% type 2 rule suppresses the space that would normally be generated by a |
| 563 |
% previous type 1 rule (e.g. =\belowrulesep= after a =\toprule=) and |
| 564 |
% replaces it by the argument of the type 2 rule. Similarly, in the |
| 565 |
% combination \{type 2 rule\}\{type 1 rule\}, the ordinary space above |
| 566 |
% the type 1 rule (e.g. =\aboverulesep=) is suppressed. But in the |
| 567 |
% combination \{type 2 rule\}\{type 2 rule\}, no space is suppressed: |
| 568 |
% the rules will be separated by both the first rule's |
| 569 |
% ={=\meta{belowspace}=}= and the second rule's ={=\meta{abovespace}=}= |
| 570 |
% arguments. Last but not least, the combination \{type 1 rule\}\{type 1 |
| 571 |
% rule\} will always give rules separated by =\doublerulesep=, |
| 572 |
% suppressing all normal space generated between the rules (but |
| 573 |
% retaining normal space above the first and below the second). |
| 574 |
% |
| 575 |
% As an exception to this last exception, `type 1 rule' excludes |
| 576 |
% =\cmidrule=. Such rules combine with other =\cmidrule=s and |
| 577 |
% =\morecmidrules= in normal use as described above. I don't know and |
| 578 |
% I don't care |
| 579 |
% care what the combination =\toprule\cmidrule{1-2}\midrule= would |
| 580 |
% produce. I can see no excuse for such usage. |
| 581 |
% |
| 582 |
%\vspace{1em} |
| 583 |
% The default dimensions are defined at the beginning of the macro |
| 584 |
% description section (Section \ref{code}). The user can change |
| 585 |
% these defaults in the preamble, or outside a |
| 586 |
% tabular environment, by simply |
| 587 |
% inserting a command in exactly the same format as in Section \ref{code}; the |
| 588 |
% redefinition will stay in effect for the rest of the document |
| 589 |
% or until redefined again. \emph{Inside a table} you would have to make the |
| 590 |
% assignment globally in a =noalign= group: |
| 591 |
% e.g. \verb|\noalign\{\global\abovetopsep=1em\toprule}|. I hope |
| 592 |
% you never have to do that. |
| 593 |
% |
| 594 |
% \section{Acknowledgments} |
| 595 |
% Hugely indebted of course to DEK and Lamport; the optional |
| 596 |
% argument and =\cmidrule= |
| 597 |
% stuff especially was stolen from =latex.sty=. |
| 598 |
% The documentation driver stuff is stolen from the |
| 599 |
% tools package description =dcolumn.dtx= by David Carlisle. |
| 600 |
% |
| 601 |
% For beta testing and encouragement ... |
| 602 |
% |
| 603 |
% \StopEventually |
| 604 |
% |
| 605 |
% \section{The code\label{code}} |
| 606 |
% |
| 607 |
% The current version is defined at the top of the file looking |
| 608 |
% something like this |
| 609 |
% \begin{macrocode} |
| 610 |
%<*package> |
| 611 |
%\NeedsTeXFormat{LaTeX2e} |
| 612 |
%\ProvidesPackage{booktabs} |
| 613 |
% [\filedate\space version\fileversion] |
| 614 |
% \end{macrocode} |
| 615 |
% |
| 616 |
% First we set up the new dimensions described above: |
| 617 |
% \begin{macrocode} |
| 618 |
\newdimen\heavyrulewidth |
| 619 |
\newdimen\lightrulewidth |
| 620 |
\newdimen\cmidrulewidth |
| 621 |
\newdimen\belowrulesep |
| 622 |
\newdimen\belowbottomsep |
| 623 |
\newdimen\aboverulesep |
| 624 |
\newdimen\abovetopsep |
| 625 |
\newdimen\cmidrulesep |
| 626 |
\newdimen\cmidrulekern |
| 627 |
\newdimen\defaultaddspace |
| 628 |
\heavyrulewidth=.08em |
| 629 |
\lightrulewidth=.05em |
| 630 |
\cmidrulewidth=.03em |
| 631 |
\belowrulesep=.65ex |
| 632 |
\belowbottomsep=0pt |
| 633 |
\aboverulesep=.4ex |
| 634 |
\abovetopsep=0pt |
| 635 |
\cmidrulesep=\doublerulesep |
| 636 |
\cmidrulekern=.5em |
| 637 |
\defaultaddspace=.5em |
| 638 |
% \end{macrocode} |
| 639 |
% And some internal counters of no interest to the end user: |
| 640 |
% \changes{v1.618}{2003/03/28}{Remove \cs{@cmidrulewidth} } |
| 641 |
% \begin{macrocode} |
| 642 |
\newcount\@cmidla |
| 643 |
\newcount\@cmidlb |
| 644 |
\newdimen\@aboverulesep |
| 645 |
\newdimen\@belowrulesep |
| 646 |
\newcount\@thisruleclass |
| 647 |
\newcount\@lastruleclass |
| 648 |
\@lastruleclass=0 |
| 649 |
\newdimen\@thisrulewidth |
| 650 |
% \end{macrocode} |
| 651 |
% which will be described as needed below. |
| 652 |
% |
| 653 |
% \begin{macro}{\futurenonspacelet} |
| 654 |
% Next we define a very useful macro (more-or-less straight from the |
| 655 |
% \TeX book's Dirty Tricks chapter; documented there). Use |
| 656 |
% =\futurenonspacelet= instead of =\futurelet= when looking for the next |
| 657 |
% (non-space) token after a macro that has an argument. (After a macro |
| 658 |
% without an argument, space is ignored anyway, so =\futurenonspacelet= |
| 659 |
% wouldn't be needed.) This hack allows users to type white |
| 660 |
% space between successive rule commands (which did not work in Version |
| 661 |
% 1.00). |
| 662 |
% \begin{macrocode} |
| 663 |
\def\futurenonspacelet#1{\def\@BTcs{#1}% |
| 664 |
\afterassignment\@BTfnslone\let\nexttoken= } |
| 665 |
\def\@BTfnslone{\expandafter\futurelet\@BTcs\@BTfnsltwo} |
| 666 |
\def\@BTfnsltwo{\expandafter\ifx\@BTcs\@sptoken\let\next=\@BTfnslthree |
| 667 |
\else\let\next=\nexttoken\fi \next} |
| 668 |
\def\@BTfnslthree{\afterassignment\@BTfnslone\let\next= } |
| 669 |
% \end{macrocode} |
| 670 |
% \end{macro} |
| 671 |
% |
| 672 |
% \subsection{Full width rules} |
| 673 |
% |
| 674 |
% When we are not in a =longtable= environment, we can simply |
| 675 |
% implement the full width rules as a =\hrule= in a =\noalign{}= |
| 676 |
% group. But within a =longtable=, the rule has to be drawn like a |
| 677 |
% =\cmidrule{1-\LT@cols}= (the rationale for this is explained in the |
| 678 |
% =longtable= documentation). |
| 679 |
% |
| 680 |
% In order to allow for both, all the rule macros have to |
| 681 |
% open a =\noalign= group immediately, while they work out whether |
| 682 |
% they have been called within a =longtable=; if you don't do this, |
| 683 |
% \TeX's underlying =\halign= process gets hiccups. |
| 684 |
% I use \LaTeX's |
| 685 |
% dirty trick (\verb?\ifnum=0`}?) to fool the parser that the bracket |
| 686 |
% count is OK. The bracket really gets closed after all the skipping |
| 687 |
% at the end of the =\@BTendrule= macro. |
| 688 |
% |
| 689 |
% The class 1 rules, and =\specialrule=, really only differ in the |
| 690 |
% defaults for space above and |
| 691 |
% below, and the width, passed to a common routine, =\@BTrule=, |
| 692 |
% described below. The spaces, =\@aboverulesep= and =\@belowrulesep=, |
| 693 |
% are set within the =\noalign= group, so are inherited by |
| 694 |
% =\@BTrule=. Similarly, =\@BTrule= knows as much as it needs to |
| 695 |
% about the routine that called it by examining the inherited |
| 696 |
% =\@thisruleclass=. The optional width argument is parsed by |
| 697 |
% =\@BTrule= after being set to default if absent. |
| 698 |
% |
| 699 |
% |
| 700 |
% \begin{macro}{\toprule} |
| 701 |
% \changes{v1.61803}{2005/04/14}{Change \cmd{\@belowrulesep} to \cmd{\belowrulesep}} |
| 702 |
% \begin{macro}{\midrule} |
| 703 |
% \begin{macro}{\bottomrule} |
| 704 |
% \begin{macro}{\specialrule} |
| 705 |
% \begin{macrocode} |
| 706 |
\def\toprule{\noalign{\ifnum0=`}\fi |
| 707 |
\@aboverulesep=\abovetopsep |
| 708 |
\global\@belowrulesep=\belowrulesep %global cos for use in the next noalign |
| 709 |
\global\@thisruleclass=\@ne |
| 710 |
\@ifnextchar[{\@BTrule}{\@BTrule[\heavyrulewidth]}} |
| 711 |
\def\midrule{\noalign{\ifnum0=`}\fi |
| 712 |
\@aboverulesep=\aboverulesep |
| 713 |
\global\@belowrulesep=\belowrulesep |
| 714 |
\global\@thisruleclass=\@ne |
| 715 |
\@ifnextchar[{\@BTrule}{\@BTrule[\lightrulewidth]}} |
| 716 |
\def\bottomrule{\noalign{\ifnum0=`}\fi |
| 717 |
\@aboverulesep=\aboverulesep |
| 718 |
\global\@belowrulesep=\belowbottomsep |
| 719 |
\global\@thisruleclass=\@ne |
| 720 |
\@ifnextchar[{\@BTrule}{\@BTrule[\heavyrulewidth]}} |
| 721 |
\def\specialrule#1#2#3{\noalign{\ifnum0=`}\fi |
| 722 |
\@aboverulesep=#2\global\@belowrulesep=#3\global\@thisruleclass=\tw@ |
| 723 |
\@BTrule[#1]} |
| 724 |
% \end{macrocode} |
| 725 |
% \end{macro} |
| 726 |
% \end{macro} |
| 727 |
% \end{macro} |
| 728 |
% \end{macro} |
| 729 |
% \begin{macro}{\addlinespace} |
| 730 |
% An =\addlinespace= is essentially a zero-width rule with |
| 731 |
% zero space above and argument (or default) space below. But because |
| 732 |
% the rule is not actually drawn, but is just a =\vskip=, there is no |
| 733 |
% need to check if we're in a longtable, so we don't need to call |
| 734 |
% =\@BTrule= as for `real' rules. But we do share the =\@BTendrule= |
| 735 |
% lookahead and flagsetting code (described below), and the =\vskip= is done there. |
| 736 |
% \begin{macrocode} |
| 737 |
\def\addlinespace{\noalign{\ifnum0=`}\fi |
| 738 |
\@ifnextchar[{\@addspace}{\@addspace[\defaultaddspace]}} |
| 739 |
\def\@addspace[#1]{\global\@belowrulesep=#1\global\@thisruleclass=\tw@ |
| 740 |
\futurelet\@tempa\@BTendrule} |
| 741 |
% \end{macrocode} |
| 742 |
% \end{macro} |
| 743 |
% |
| 744 |
% |
| 745 |
% \begin{macro}{\@BTrule} |
| 746 |
% All the rules (except =\addlinespace=) share this code. |
| 747 |
% \changes{v1.618033}{2016/04/27}{Rearranged and added \cmd{\nobreak} within longtable (Morten H{\o}gholm)} |
| 748 |
% \changes{v1.6180339}{2019/10/08}{Add test for xltabular (Herbert Voss)} |
| 749 |
% \changes{v1.61803398}{2020/01/12}{Restore \cmd{\@BTrule} to v1.618033 (Danie Els) } |
| 750 |
% \begin{macrocode} |
| 751 |
\def\@BTrule[#1]{% |
| 752 |
% \end{macrocode} |
| 753 |
% Now we work out, by a very nasty hack, if we're within a |
| 754 |
% =longtable=. It's easy if =\longtable= isn't even defined: then we |
| 755 |
% can't be. But it is not enough just to check if =longtable= is |
| 756 |
% loaded --- we might be within an ordinary table rather than a |
| 757 |
% longtable. So we look to see if =\hline= has been re-defined |
| 758 |
% from its \LaTeX\ definition to be the same as |
| 759 |
% =\LT@hline=. (Longtable currently does this redefinition when it opens a |
| 760 |
% =longtable= environment, but not globally, so it is |
| 761 |
% cleared it when the environment closes.) Another |
| 762 |
% package could potentially do this! And =longtable= might change the |
| 763 |
% way it implements this! So, it is not entirely safe, but I have |
| 764 |
% found no better way so far. |
| 765 |
% |
| 766 |
% We set up =\@BTswitch= to call =\@BTnormal= or =\@BLTrule=, as |
| 767 |
% appropriate, then call it. |
| 768 |
% \begin{macrocode} |
| 769 |
\ifx\longtable\undefined |
| 770 |
\let\@BTswitch\@BTnormal |
| 771 |
\else\ifx\hline\LT@hline |
| 772 |
\nobreak |
| 773 |
\let\@BTswitch\@BLTrule |
| 774 |
\else |
| 775 |
\let\@BTswitch\@BTnormal |
| 776 |
\fi\fi |
| 777 |
% \end{macrocode} |
| 778 |
% Call =\@BTswitch= at end of macro |
| 779 |
% \begin{macrocode} |
| 780 |
\global\@thisrulewidth=#1\relax |
| 781 |
% \end{macrocode} |
| 782 |
% Save the width argument (if the user didn't give one, then the |
| 783 |
% calling routine will have called =\@BTrule= with the default) in a global |
| 784 |
% variable for later use when drawing the rule. |
| 785 |
% \begin{macrocode} |
| 786 |
\ifnum\@thisruleclass=\tw@\vskip\@aboverulesep\else |
| 787 |
% \end{macrocode} |
| 788 |
% Specialrules always insert specified space above. (Note: addlinespaces |
| 789 |
% don't come here). |
| 790 |
% \begin{macrocode} |
| 791 |
\ifnum\@lastruleclass=\z@\vskip\@aboverulesep\else |
| 792 |
\ifnum\@lastruleclass=\@ne\vskip\doublerulesep\fi\fi\fi |
| 793 |
% \end{macrocode} |
| 794 |
% After text (last rule class 0), precede the rule by =\aboverulesep=; |
| 795 |
% but if immediately after a |
| 796 |
% previous rule, insert a =\doublerulesep=. |
| 797 |
% |
| 798 |
% \begin{macrocode} |
| 799 |
\@BTswitch} |
| 800 |
% \end{macrocode} |
| 801 |
% \end{macro} |
| 802 |
% |
| 803 |
% |
| 804 |
% \begin{macro}{\CT@arc@} |
| 805 |
% \changes{v1.6180}{2005/03/16}{add colortbl command for color support} |
| 806 |
% This is support for the colortbl package for colored |
| 807 |
% rules. \cmd{\CT@arc@} hold the \cmd{\arrayrulecolor} setting. |
| 808 |
% \begin{macrocode} |
| 809 |
\AtBeginDocument{% |
| 810 |
\providecommand*\CT@arc@{}}%% colortbl support |
| 811 |
% \end{macrocode} |
| 812 |
% \end{macro} |
| 813 |
% |
| 814 |
% |
| 815 |
% \begin{macro}{\@BTnormal} |
| 816 |
% \changes{v1.6180}{2005/03/16}{add colortbl \cmd{\CT@arc@} command for color support} |
| 817 |
% This is when we're \emph{not} within a longtable. We are already in a |
| 818 |
% =\noalign= group, all we need do is draw an =\hrule= and gobble any |
| 819 |
% trailing spaces, then call the closing routine with =\@tempa= set |
| 820 |
% equal to the next token in the document. |
| 821 |
% |
| 822 |
% \begin{macrocode} |
| 823 |
\def\@BTnormal{% |
| 824 |
{\CT@arc@\hrule\@height\@thisrulewidth}% |
| 825 |
\futurenonspacelet\@tempa\@BTendrule} |
| 826 |
% \end{macrocode} |
| 827 |
% \end{macro} |
| 828 |
% |
| 829 |
% \begin{macro}{\@BLTrule} |
| 830 |
% This is for full width rule within a =longtable=. First we check if |
| 831 |
% a kerning argument has been used; if so let =\@@BLTrule= read it, |
| 832 |
% else call =\@@BLTrule= with an empty string: |
| 833 |
% \begin{macrocode} |
| 834 |
\def\@BLTrule{\@ifnextchar({\@@BLTrule}{\@@BLTrule()}} |
| 835 |
% \end{macrocode} |
| 836 |
% \end{macro} |
| 837 |
% \begin{macro}{\@@BLTrule} |
| 838 |
% \begin{macrocode} |
| 839 |
\def\@@BLTrule(#1){\@setrulekerning{#1}% |
| 840 |
\global\@cmidlb\LT@cols |
| 841 |
% \end{macrocode} |
| 842 |
% The =\@setrulekerning= routine parses the kerning argument tokens |
| 843 |
% and sets global kerning widths accordingly (or to defaults, if user |
| 844 |
% hasn't set them explicitly). The global assignment to =\@cmidlb= |
| 845 |
% sets up the column count for the =\@cmidruleb= macro, which is |
| 846 |
% shared with =cmidrules=. |
| 847 |
% \begin{macrocode} |
| 848 |
\ifnum0=`{\fi}% |
| 849 |
% \end{macrocode} |
| 850 |
% Close the currently open =\noalign= group. Within a =longtable=, |
| 851 |
% rules are all to be drawn as leaders within a text box that is |
| 852 |
% =\LT@cols= columns wide. |
| 853 |
% \begin{macrocode} |
| 854 |
\@cmidruleb |
| 855 |
% \end{macrocode} |
| 856 |
% Draw the rule. We share the =\@cmidruleb= code with ordinary =\cmidrule=s. |
| 857 |
% \begin{macrocode} |
| 858 |
\noalign{\ifnum0=`}\fi |
| 859 |
% \end{macrocode} |
| 860 |
% We have to open a new noalign immediately else \TeX will start a new |
| 861 |
% text box where we don't want one. Then, after gobbling any |
| 862 |
% unwanted white space, we call the closing routine. |
| 863 |
% \begin{macrocode} |
| 864 |
\futurenonspacelet\@tempa\@BTendrule} |
| 865 |
% \end{macrocode} |
| 866 |
% \end{macro} |
| 867 |
% \begin{macro}{\@BTendrule} |
| 868 |
% We look one step ahead (token is in =\@tempa=) to see if another |
| 869 |
% rule follows (shame on user!). If so, we set =\@lastruleclass= equal |
| 870 |
% to =\@thisruleclass= (thus setting it up for the following rule). If |
| 871 |
% there isn't a following rule, we clear =\@lastruleclass= (ie set it |
| 872 |
% to zero), which isn't technically true since we have just drawn a |
| 873 |
% rule, but sets it up correctly for the next rule encountered, which |
| 874 |
% must be following some intervening text. |
| 875 |
% \begin{macrocode} |
| 876 |
\def\@BTendrule{\ifx\@tempa\toprule\global\@lastruleclass=\@thisruleclass |
| 877 |
\else\ifx\@tempa\midrule\global\@lastruleclass=\@thisruleclass |
| 878 |
\else\ifx\@tempa\bottomrule\global\@lastruleclass=\@thisruleclass |
| 879 |
\else\ifx\@tempa\cmidrule\global\@lastruleclass=\@thisruleclass |
| 880 |
\else\ifx\@tempa\specialrule\global\@lastruleclass=\@thisruleclass |
| 881 |
\else\ifx\@tempa\addlinespace\global\@lastruleclass=\@thisruleclass |
| 882 |
\else\global\@lastruleclass=\z@\fi\fi\fi\fi\fi\fi |
| 883 |
\ifnum\@lastruleclass=\@ne\relax\else\vskip\@belowrulesep\fi |
| 884 |
\ifnum0=`{\fi}} |
| 885 |
% \end{macrocode} |
| 886 |
% \end{macro} |
| 887 |
% |
| 888 |
% |
| 889 |
% \subsection{Special subrules} |
| 890 |
% |
| 891 |
% \begin{macro}{\@setrulekerning} |
| 892 |
% The following code parses the trimming arguments (if there are any) |
| 893 |
% for =\cmidrule= or a =\BLTrule=. The rule |
| 894 |
% will be trimmed left and right by =\cmrkern@l= and =\cmrkern@l=, |
| 895 |
% which are zero by default, set to =\cmidrulekern= by the plain |
| 896 |
% =(lr)= arguments, or user set as in =(r{.5em})=. We parse token by |
| 897 |
% token through the arguments. The |
| 898 |
% tokens =r= and =l= cause =\cmrkern@r= or =\cmrkern@l= to be set to |
| 899 |
% =\cmidrulekern=. There is no lookahead to see if a width is the |
| 900 |
% next token; this strategy is efficient for the plain commands, |
| 901 |
% while inefficient for the qualified commands, but more importantly |
| 902 |
% it is much easier to program. Tokens =r= and =l= also set |
| 903 |
% =\cmrswitch= so that if the next token turns out to be |
| 904 |
% ={=\meta{wd}=}= then the kerning will be done on the side |
| 905 |
% currently specified. I have been too lazy to program an error |
| 906 |
% message should one encounter tokens other than =r=, =l= or |
| 907 |
% ={=\meta{wd}=}=. |
| 908 |
% \changes{v1.6180}{2005/03/16}{Refine option testing in \cmd{\@setrulekerning}} |
| 909 |
% \begin{macrocode} |
| 910 |
\def\@setrulekerning#1{% |
| 911 |
\global\let\cmrkern@l\z@ |
| 912 |
\global\let\cmrkern@r\z@ |
| 913 |
\@tfor\@tempa :=#1\do |
| 914 |
{\def\@tempb{r}% |
| 915 |
\ifx\@tempa\@tempb |
| 916 |
\global\let\cmrkern@r\cmidrulekern |
| 917 |
\def\cmrsideswitch{\cmrkern@r}% |
| 918 |
\else |
| 919 |
\def\@tempb{l}% |
| 920 |
\ifx\@tempa\@tempb |
| 921 |
\global\let\cmrkern@l\cmidrulekern |
| 922 |
\def\cmrsideswitch{\cmrkern@l}% |
| 923 |
\else |
| 924 |
\global\expandafter\let\cmrsideswitch\@tempa |
| 925 |
\fi |
| 926 |
\fi}} |
| 927 |
% \end{macrocode} |
| 928 |
% \end{macro} |
| 929 |
% \begin{macro}{\cmidrule} |
| 930 |
% \begin{macro}{\@cmidrule} |
| 931 |
% \begin{macro}{\@@cmidrule} |
| 932 |
% \begin{macro}{\@@@cmidrule} |
| 933 |
% The =\cmidrule= re-uses =\@lastruleclass= in an entirely different |
| 934 |
% way from the full width rules. (Maybe I should have used a |
| 935 |
% different flag; it seemed efficient at the time \ldots). This |
| 936 |
% is (left) set to one if you are in the middle of a row of |
| 937 |
% =\cmidrules=, or starting a new one (with =\morecmidrules=). |
| 938 |
% Otherwise, when =\@lastruleclass= is zero, we precede the |
| 939 |
% rule with =\aboverulesep=. |
| 940 |
% \begin{macrocode} |
| 941 |
\def\cmidrule{\noalign{\ifnum0=`}\fi |
| 942 |
\@ifnextchar[{\@cmidrule}{\@cmidrule[\cmidrulewidth]}} |
| 943 |
\def\@cmidrule[#1]{\@ifnextchar({\@@cmidrule[#1]}{\@@cmidrule[#1]()}} |
| 944 |
\def\@@cmidrule[#1](#2)#3{\@@@cmidrule[#3]{#1}{#2}} |
| 945 |
% \end{macrocode} |
| 946 |
% The above is fiddling around to set defaults for missing optional |
| 947 |
% arguments. We also pass to =\@@@cmidrule= in a different order, |
| 948 |
% namely =[a-b]=={width required}= ={kerning commands}= (this being |
| 949 |
% the order in which the arguments are actually processed): |
| 950 |
% \begin{macrocode} |
| 951 |
\def\@@@cmidrule[#1-#2]#3#4{\global\@cmidla#1\relax |
| 952 |
\global\advance\@cmidla\m@ne |
| 953 |
\ifnum\@cmidla>0\global\let\@gtempa\@cmidrulea\else |
| 954 |
\global\let\@gtempa\@cmidruleb\fi |
| 955 |
\global\@cmidlb#2\relax |
| 956 |
\global\advance\@cmidlb-\@cmidla |
| 957 |
% \end{macrocode} |
| 958 |
% This has set up a switch (=\@gtempa=) to call the relevant routine, |
| 959 |
% =\@cmidrulea= or =\@cmidruleb=, depending on whether we start |
| 960 |
% from column one or not. |
| 961 |
% \begin{macrocode} |
| 962 |
\global\@thisrulewidth=#3 |
| 963 |
% \end{macrocode} |
| 964 |
% That is, set per default or given argument. Then parse any trimming |
| 965 |
% arguments to set, globally, =\cmrkern@r= and =\cmrkern@l= accordingly: |
| 966 |
% \begin{macrocode} |
| 967 |
\@setrulekerning{#4} |
| 968 |
% \end{macrocode} |
| 969 |
% Now insert space above if needed, close the =\noalign=, |
| 970 |
% then switch to appropriate rule drawing routine as determined |
| 971 |
% above (=\let= to =\@gtempa=): |
| 972 |
% \begin{macrocode} |
| 973 |
\ifnum\@lastruleclass=\z@\vskip \aboverulesep\fi |
| 974 |
\ifnum0=`{\fi}\@gtempa |
| 975 |
% \end{macrocode} |
| 976 |
% Having now drawn the rule, |
| 977 |
% open another =\noalign=, and call the closing routine: |
| 978 |
% \begin{macrocode} |
| 979 |
\noalign{\ifnum0=`}\fi\futurenonspacelet\@tempa\@xcmidrule} |
| 980 |
% \end{macrocode} |
| 981 |
% \end{macro} |
| 982 |
% \end{macro} |
| 983 |
% \end{macro} |
| 984 |
% \end{macro} |
| 985 |
% |
| 986 |
% \begin{macro}{\@xcmidrule} |
| 987 |
% In this closing routine, see if another =\cmidrule= follows; |
| 988 |
% if so, backspace |
| 989 |
% vertical so it will line up with the one you just drew, |
| 990 |
% and setting =\@lastruleclass= to 1 will suppress |
| 991 |
% adding space above the next. If a =\morecimdrules= follows, |
| 992 |
% we add (positive) =\cmidrulesep= (and again set =\@lastruleclass= |
| 993 |
% to one). Otherwise this is the last rule of the current group |
| 994 |
% and we can just add =\belowrulesep=. Finally, we close the =\noalign=. |
| 995 |
% \changes{v1.618}{2003/03/28}{Change to \cmd{\@xcmidrule}: |
| 996 |
% replace \cmd{\@cmidrulewidth} with \cmd{\@thisrulewidth }} |
| 997 |
% \begin{macrocode} |
| 998 |
\def\@xcmidrule{% |
| 999 |
\ifx\@tempa\cmidrule |
| 1000 |
\vskip-\@thisrulewidth |
| 1001 |
\global\@lastruleclass=\@ne |
| 1002 |
\else \ifx\@tempa\morecmidrules |
| 1003 |
\vskip \cmidrulesep |
| 1004 |
\global\@lastruleclass=\@ne\else |
| 1005 |
\vskip \belowrulesep |
| 1006 |
\global\@lastruleclass=\z@ |
| 1007 |
\fi\fi |
| 1008 |
\ifnum0=`{\fi}} |
| 1009 |
% \end{macrocode} |
| 1010 |
% \end{macro} |
| 1011 |
% \begin{macro}{\@cmidrulea} |
| 1012 |
% This code (called below) actually draws the rules. They are drawn |
| 1013 |
% as boxes in text, rather than in a =\noalign= group, which permits |
| 1014 |
% the left and right kerning. |
| 1015 |
% \changes{v1.6180}{2005/03/16}{add colortbl \cmd{\CT@arc@} command for color support} |
| 1016 |
% \changes{v1.618033}{2016/04/27}{add \cmd{\kern}\cmd{\z@} after \cmd{\hfill} to protects against unskips} |
| 1017 |
% \begin{macrocode} |
| 1018 |
\def\@cmidrulea{% |
| 1019 |
\multispan\@cmidla&\multispan\@cmidlb |
| 1020 |
\unskip\hskip\cmrkern@l% |
| 1021 |
{\CT@arc@\leaders\hrule \@height\@thisrulewidth\hfill\kern\z@}% |
| 1022 |
\hskip\cmrkern@r\cr}% |
| 1023 |
% \end{macrocode} |
| 1024 |
% \end{macro} |
| 1025 |
% \begin{macro}{\@cmidruleb} |
| 1026 |
% \changes{v1.6180}{2005/03/16}{add colortbl \cmd{\CT@arc@} command for color support} |
| 1027 |
% \changes{v1.618033}{2016/04/27}{add \cmd{\kern}\cmd{\z@} after \cmd{\hfill} to protects against unskips} |
| 1028 |
% \begin{macrocode} |
| 1029 |
\def\@cmidruleb{% |
| 1030 |
\multispan\@cmidlb |
| 1031 |
\unskip\hskip \cmrkern@l% |
| 1032 |
{\CT@arc@\leaders\hrule \@height\@thisrulewidth\hfill\kern\z@}% |
| 1033 |
\hskip\cmrkern@r\cr}% |
| 1034 |
% \end{macrocode} |
| 1035 |
% \end{macro} |
| 1036 |
% |
| 1037 |
% \begin{macro}{\morecmidrules} |
| 1038 |
% This is really a dummy command; all the work is done above |
| 1039 |
% within the =\cmidrule= routine. We look one step ahead there |
| 1040 |
% to see if a =\morecmidrules= follows the current =\cmidrule=, |
| 1041 |
% and if so set the flag. Otherwise, =\morecmidrules= itself |
| 1042 |
% does nothing. |
| 1043 |
% \begin{macrocode} |
| 1044 |
\def\morecmidrules{\noalign{\relax}} |
| 1045 |
% \end{macrocode} |
| 1046 |
% \end{macro} |
| 1047 |
% |
| 1048 |
% \begin{macrocode} |
| 1049 |
%</package> |
| 1050 |
% \end{macrocode} |
| 1051 |
% |
| 1052 |
% \Finale |
| 1053 |
% |