summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/plain/zztex/zztabularv3.tex
blob: c7035daa73c7bc1ab43f659090b9f03e1c0bb399 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Module:    ZzTeX Tabular Facilities, version 3
%
% Synopsis:  This module contains all the facilities for producing
%            tabular material. This is the third major version.
%
% Author:    Paul C. Anagnostopoulos
% Created:   4 June 2004
%
% Copyright 1989--2020 by Paul C. Anagnostopoulos
% under The MIT License (opensource.org/licenses/MIT)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%                       Tabular Block
%                       ------- -----


\defineblock{\tabular}{\endtabular}{\false}{}

%~block tabular Type
% \abovepenalty = integer               % Penalty above text.
% \aboveskip = glue                     % Space b/b above text.
% \belowpenalty = integer               % Penalty below text.
% \belowskip = glue                     % Space b/b below text.
% \bodyfont = {font}                    % Body font.
% \columngutter = glue                  % Width of column gutter.
% \colheadbelowskip = dimen             % Space b/b below column heads.
% \colheadcolor = {color}               % Color of Column heads.
% \colheadfont = {font}                 % Column head font.
% \interrowskip = dimen                 % Extra space between rows.
% \leftindent = glue                    % Left indentation.
% \parhang = dimen                      % Paragraph column hang.
% \parrag = dimen                       % Paragraph raggedness.
% \parskip = skip                       % Paragraph skip.
% \rightindent = glue                   % Right indentation.
% \rulecolcolor = {color}               % Color of table rules.
% \rulecolwidth = dimen                 % Width of column rules.
% \sideheadaboveskip = dimen            % Space b/b above side heads.
% \sideheadbelowskip = dimen            % Space b/b below side heads.
% \sideheadcolor = {color}              % Color of side heads.
% \sideheadfont = {font}                % Side head font.
% \spannerheadcolor = {color}           % Color of spanner heads.
% \spannerheadfont = {font}             % Spanner head font.
% \spannerruleaboveskip = dimen         % Space b/b above spanner rules.
% \spannerrulebelowskip = dimen         % Space b/b below spanner rules.
% \spannerrulecolor = {color}           % Color of spanner rules.
% \spannerruleheight = dimen            % Spanner rule thickness.
% \style = {...}                        % Style description.
% \tabbottomruleaboveskip = dimen       % Space b/b above bottom rules.
% \tabheadrulebelowskip = dimen         % Space b/b below head rules.
% \def \tabnoteformat ##1{...}          % Format of table note references.
% \tabrulecolor = {color}               % Color of table rules.
% \tabruleheight = dimen                % Table rule thickness.
% \tabtoprulebelowskip = dimen          % Space b/b below top rules.
% \width = dimen                        % Width of tabular material.
%~end

\defineskip{\colheadbelowskip}{0pt}
\definetoks{\colheadcolor}
\definetoks{\colheadfont}
\definetoks{\rulecolcolor}
\definedimen{\rulecolwidth}{0pt}
\definedimen{\sideheadaboveskip}{0pt}
\definedimen{\sideheadbelowskip}{0pt}
\definetoks{\sideheadcolor}
\definetoks{\sideheadfont}
\definetoks{\spannerheadcolor}
\definetoks{\spannerheadfont}
\definedimen{\spannerruleaboveskip}{0pt}
\definedimen{\spannerrulebelowskip}{0pt}
\definetoks{\spannerrulecolor}
\definedimen{\spannerruleheight}{0pt}
\definedimen{\tabbottomruleaboveskip}{0pt}
\definedimen{\tabheadrulebelowskip}{0pt}
\definetoks{\tabrulecolor}
\definedimen{\tabruleheight}{0pt}
\definedimen{\tabtoprulebelowskip}{0pt}


\def \tabular #1#2{%                            {type}{template}
  \endgraf
  \beginblockscope{tabular}%
  \global\increment \tabulardepth
  \abovepenalty = \breakgood                    %~default hard
  \belowpenalty = \breakbetter                  %~default hard
  \processdesign{\tabular}{#1}%
  \global\increment \tabularnumber
  \zsetuptabular{#2}%
  \tabularformat
  \defineatsigncommand @A{\adjustcolrule}%
  \defineatsigncommand @C{\closeuprows}%
  \defineatsigncommand @N{\nocolrule}%
  \defineatsigncommand @S{\skipabovespannerrule}%
  \defineatsigncommand @T{\skipbelowspannerrule}%
  \offinterlineskip
  \nobreak
  \tabskip=\leftskip
  \halign \if \dimneqlp{\width}{\naturalwidth}to \width \fi \bgroup
    \span\the\zpreamble \tabskip=\rightskip \cr}

\def \endtabular {%
    \crcr
  \egroup % \halign
  \if \posp{\prevdepth}%                % Does the last line have a strut?
    \kern -.5\interrowskip              % Yes, eliminate extra depth from
    \prevdepth = \dp\strutbox           % \interrowskip.
  \else
    \prevdepth = \tabruleheight         % No, compensate for bottom rule.
  \fi
  \futurelet\nexttoken \zendtabular}

\def \zendtabular {%
  \endtabularformat
  \global\decrement \tabulardepth
  \endblockscope{tabular}%
  \parnext}

\def \tabularformat {%
  \bbskipabove{\abovepenalty}{\aboveskip}%
  \fakepar                                      % This empty paragraph allows
  \hbox{}%                                      % the \bbskipabove to work.
  \kern
    \if \dimzerop{\tabtoprulebelowskip}-\ht\zrowstrut \else -\tabruleheight \fi
  \alterindentation{\leftindent}{\rightindent}}

\def \endtabularformat{%
  \bbskipbelowblockpar{\nexttoken}{\belowpenalty}{\belowskip}}

\def \adjustcolumngutter #1{%                   {amount} %^tabular
  \with{\advance\columngutter by #1}}

\def \adjustinterrowskip #1{%                   {amount} %^tabular
  \with{\advance\interrowskip by #1}}

%                       Set Up Tabular
%                       --- -- -------


\definecount{\tabcolcount}{0}           % Number of columns in table.
\definetoks{\zpreamble}                 % Preamble for \halign.
\definetoks{\ztabspacerow}              % Special row for vertical spacing.
\definebox{\zrowstrut}                  % Strut for table rows.
\definebox{\zparcelltopstrut}           % Strut for first line of par cell.
\definebox{\zparcellbotstrut}           % Strut for last line of par cell.

\def \zsetuptabular #1{%                                {template}
  \zanaltemplate{#1}%
  \the\bodyfont
  \calculate \tdimena = {\interrowskip,/,2,+,\ht\strutbox}%
  \calculate \tdimenb = {\interrowskip,/,2,+,\dp\strutbox}%
  \setbox \zrowstrut = \hbox{\vrule width 0pt
                                    height \tdimena depth \tdimenb}%
  \setbox \zparcelltopstrut = \hbox{\vrule width 0pt
                                           height \tdimena depth 0pt}%
  \setbox \zparcellbotstrut = \hbox{\vrule width 0pt
                                           height 0pt depth \tdimenb}%
  \global\zprevrowclass = \zrcpream
  \global\zcurrowclass = \zrcpream
  \gdef \zcolrulegate {}%
  \global\setflag \zcolrulesenabled = \false
  \everycr = {\noalign{\ztabcr}}}

%                       Analyze Template
%                       ------- --------


\defineskip{\zpendgutter}{0pt}


\def \zanaltemplate #1{%                                {template}
  \setbox\zboxa = \hbox{%
    \defineatsigncommand @!{\zcustomrulecol}%
    \defineatsigncommand @>{\zgutterspec}%
    \defineatsigncommand @c{\zcentercol}%
    \defineatsigncommand @C{\zcenternumbercol}%
    \defineatsigncommand @e{\zemptycol}%
    \defineatsigncommand @l{\zleftcol}%
    \defineatsigncommand @L{\zleftnumbercol}%
    \defineatsigncommand @p{\zparcol}%
    \defineatsigncommand @r{\zrightcol}%
    \defineatsigncommand @R{\zrightnumbercol}%
    \defineatsigncommand @s{\zspecialcol}%
    \defineatsigncommand @|{\zrulecol}%
    \global\tabcolcount = 0
    \global\zpreamble = {}%
    \global\ztabspacerow = {}%
    #1}%
  \tabcolcount = \tabcolcount
  \zpreamble = \zpreamble
  \ztabspacerow = \ztabspacerow}

\def \zcentercol {%
  \zstartcol{\false}%
  \zappendpreamble{\hfil ##\rowstrut \hfil}}

\def \zcenternumbercol #1{%
  \zstartcol{\false}%
  \zmeasuredanumber #1..\zmark
  \edef \znext {%
    \noexpand\zappendpreamble{%
      \hfil \noexpand\zsetnumbercell{\the\tdimena}{\the\tdimenb}{####}\hfil}}%
  \znext}

\def \zcustomrulecol #1#2{%                             {color}{width}
  \if \dimeqlp{\zpendgutter}{\mindimen}\zpendgutter = .5\columngutter \fi
  \zstartcol{\true}%
  \zappendpreamble{\zsetcolrule{#1}{#2}{##}}%
  \zpendgutter = .5\columngutter}

\def \zemptycol #1{%                                    {width}
  \zstartcol{\false}%
  \zappendpreamble{##\rowstrut \hspace{#1}}}

\def \zgutterspec #1{%                                  {width}
  \zparsegutterspec #1*\zmark}

\def \zparsegutterspec #1*#2\zmark{%
  \zpendgutter = #1\relax
  \if \notp{\emptyargp{#2}}%
    \advance \zpendgutter by \columngutter
    \advance \zpendgutter by -1\columngutter
  \fi}

\def \zleftcol {%
  \zstartcol{\false}%
  \zappendpreamble{##\rowstrut \hfil}}

\def \zleftnumbercol #1{%
  \zstartcol{\false}%
  \zmeasuredanumber #1..\zmark
  \edef \znext {%
    \noexpand\zappendpreamble{%
      \noexpand\zsetnumbercell{\the\tdimena}{\the\tdimenb}{####}\hfil}}%
  \znext}

\def \zparcol #1{%                                      {width}
  \zstartcol{\false}%
  \zappendpreamble{\zsetparcol{#1}{##}}}

\def \zrightcol {%
  \zstartcol{\false}%
  \zappendpreamble{\hfil ##\rowstrut}}

\def \zrightnumbercol #1{%
  \zstartcol{\false}%
  \zmeasuredanumber #1..\zmark
  \edef \znext {%
    \noexpand\zappendpreamble{%
      \hfil \noexpand\zsetnumbercell{\the\tdimena}{\the\tdimenb}{####}}}%
  \znext}

\def \zrulecol {%
  \if \dimeqlp{\zpendgutter}{\mindimen}\zpendgutter = .5\columngutter\relax \fi
  \zstartcol{\true}%
  \zappendpreamble{\zsetcolrule{}{}{##}}%
  \zpendgutter = .5\columngutter\relax}

\def \zspecialcol #1{%                                  {template}
  \zstartcol{\false}%
  \zappendpreamble{#1\rowstrut}}

\def \zstartcol #1{%                                    {rule-column?}
  \if \posp{\tabcolcount}%
    \if \dimeqlp{\zpendgutter}{\mindimen}\zpendgutter = \columngutter \fi
    \edef \znext {\noexpand\zappendpreamble{\tabskip=\the\zpendgutter &}}%
    \znext
    \global\ztabspacerow = \expandafter{\the\ztabspacerow &}%
  \fi
  \global\increment \tabcolcount
  \if \notp{#1}%
    \global\ztabspacerow = \expandafter{\the\ztabspacerow
                                        \omit \copy \ztabvspacebox}%
  \fi
  \zpendgutter = \mindimen}

\def \zappendpreamble #1{%                                 {preamble stuff}
  \global\zpreamble = \expandafter{\the\zpreamble #1}}

%                       Preamble Helpers
%                       -------- -------


\def \zmeasuredanumber #1.#2.#3\zmark{%
  \measuretextwidth{\tdimena}{#1}%
  \measuretextwidth{\tdimenb}{.#2}%
  \if \andp{\emptyargp{#2}}{\emptyargp{#3}}\tdimenb = 0pt\fi}

\def \zsetcolrule #1#2#3{%                      {color}{width}{adjustment}
  \if \emptyargp{#1}\color{\the\tabrulecolor}\else \color{#1}\fi
  \vrule width \if \emptyargp{#2}\rulecolwidth \else #2\fi
         \zcolrulegate #3%
  \endcolor}

\def \zsetnumbercell #1#2#3{%                   {pre-width}{post-width}{text}
  \gdef \zcellstyle {}%
  \zsplitdanumber #3..\zmark
  \if \dimzerop{#2}%
    \if \emptytoksp{\ztoksb}%
      \hbox to #1{\hfil \the\ztoksa}%
    \else
      \error{celldecpt}{Template picture did not include a decimal point}%
    \fi
  \else
    \hbox to #1{\hfil \the\ztoksa}%
    \hbox to #2{\zcellstyle \the\ztoksb \hfil}%
  \fi
  \rowstrut}

\long\def \zsetparcol #1#2{%                    {width}{text}
  \vtop{%
    \zpushvcontext
    \baselineskip = \normalbaselineskip
    \lineskiplimit = 0pt \lineskip = 0pt
%%%    \setindentation{0pt}{0pt}%
    \settextwidth{#1}%
    \setparrag{\parrag}%
    \leftskip = \parhang
    \parindent = -\parhang
    \parfillskip = \normalparfillskip
    \unhcopy \zparcelltopstrut
    #2%
    \if \hmodep \unhcopy \zparcellbotstrut \par \fi
    \zpopvcontext}}

\def \zsplitdanumber #1.#2.#3\zmark{%
  \ztoksa = {#1}%
  \ztoksb = {.#2}%
  \if \andp{\emptyargp{#2}}{\emptyargp{#3}}\ztoksb = {}\fi}

%                       Row Class
%                       --- -----


\definecount{\zprevrowclass}{0}
\definecount{\zcurrowclass}{0}

\chardef \zrcpream  = 0
\chardef \zrcdata   = 1
\chardef \zrchead   = 2
\chardef \zrcrule   = 3
\chardef \zrcvspace = 4
\chardef \zrcbbskip = 5

\def \zsetrowclass #1{%
  \if \gtrp{#1}{\zcurrowclass}\global\zcurrowclass = #1\relax \fi}

\def \ztabcr {%
  \global\zprevrowclass = \zcurrowclass
  \global\zcurrowclass = \zrcdata
  \global\setflag \zcolrulesenabled = \false}

%                       Cell Facilities
%                       ---- ----------


%~ This command produces a phantom zero, which is useful for aligning
%~ numbers when decimal-aligned columns are not being used.

\def \0{\phantom{0}}                                    %^tabular

\zremovePlaindef \hideskip
\defineskip{\hideskip}{-1000pt plus 1fill}

%~ This command "hides" the width of the cell from the column width calculation
%~ process. The cell does not participate in determining the widest cell of
%~ the column. If the cell is wider than the calculated column width, it will
%~ stick into the left or right column gutter, depending on the position of the
%~ |\hidewidth| command.

\def \hidewidth {\hskip \hideskip}                      %^tabular

%~ This command discards the templates for the specified number of columns and
%~ creates one cell that spans them all. The content of the cell is specified
%~ immediately following the command. This spanning cell has no template, so
%~ you must include all the required commands in the cell text. This is usually done
%~ using one of the cell override commands such as |\leftcell|.

\def \multispan #1{%                                    {columns} %^tabular
  \omit
  \tcounta = #1%
  \loop \ifnum \tcounta > 1 \zspan \repeat
  \let \omit = \relax % In case the next thing is a \leftcell or whatever.
  \ignorespaces}

\def \zspan {\span\omit \decrement \tcounta}

\def \rowstrut {%
  \unhcopy \zrowstrut}

\def \zcellstyle {}

\def \setcellstyle #1{%
  #1%
  \gdef \zcellstyle {#1}%
  \ignorespaces}

%~ This command sets a table note reference, usually a lowercase
%~ letter. The format of the reference is determined by the design.

\def \tabnote #1{%                                      {note-mark} %^tabular
  {\tabnoteformat{#1}}}

%                       Cell Overrides
%                       ---- ---------


%~ This command overrides the template for the column and sets
%~ a centered cell. It must appear immediately after the
%~ ampersand (|&&|) that begins the cell.

\def \centercell #1{%                                   {text} %^tabular
  \omit
  \hfil #1\rowstrut \hfil}

%~ This command overrides the template for the column and sets
%~ a flush left cell. It must appear immediately after the
%~ ampersand (|&&|) that begins the cell.

\def \leftcell #1{%                                     {text} %^tabular
  \omit
  #1\rowstrut \hfil}

%~ This command overrides the template for the column and sets
%~ a paragraph cell. It must appear immediately after the
%~ ampersand (|&&|) that begins the cell.

\def \parcell #1#2{%                                    {width}{text} %^tabular
  \omit
  \zsetparcol{#1}{#2}}

%~ This command overrides the template for the column and sets
%~ a flush right cell. It must appear immediately after the
%~ ampersand (|&&|) that begins the cell.

\def \rightcell #1{%                                    {text} %^tabular
  \omit
  \hfil #1\rowstrut}

%                       Column Heads
%                       ------ -----


%~ This column head command produces a centered head.

\def \centerhead #1{%                                   {heading} %^tabular
  \centercell{%
    \the\colheadfont \colortext{\the\colheadcolor}{#1}%
    \zchkadjheads}}

%~ This column head command produces a flush left head.

\def \lefthead #1{%                                     {heading} %^tabular
  \leftcell{%
    \the\colheadfont \colortext{\the\colheadcolor}{#1}%
    \zchkadjheads}}

%~ This column head command produces a flush right head.

\def \righthead #1{%                                    {heading} %^tabular
  \rightcell{%
    \the\colheadfont \colortext{\the\colheadcolor}{#1}%
    \zchkadjheads}}

%~ This command produces a spanner head that spans the specified
%~ number of columns.

\def \spannerhead #1#2{%                                {columns}{heading} %^tabular
  \multispan{#1}%
  \centercell{\the\spannerheadfont \colortext{\the\spannerheadcolor}{#2}}%
  \zsetrowclass{\zrchead}}

\def \zchkadjheads {%
  \if \andp{\eqlp{\zprevrowclass}{\zrchead}}{\posp{\interrowskip}}%
    \warning{adjheads}{Two adjacent rows of heads need to be closed up}%
    \global\zprevrowclass = \zrcdata
  \fi
  \zsetrowclass{\zrchead}}

%                       Side Heads
%                       ---- -----

%~ This command is a shorthand for producing a cut-in head that spans the
%~ entire width of the table. It is equivalent to:
%~
%~ | \skipabovesidehead
%~ | \sidehead{*all-columns*}{*heading*}\cr
%~ | \skipbelowsidehead

\def \cutinhead #1{%                                    {heading} %^tabular
  \skipabovesidehead
  \sidehead{\tabcolcount}{#1}\cr
  \skipbelowsidehead}

%~ This command produces a side head that spans the specified number of
%~ columns. It is similar to |\spannerhead|. It is almost always the case that a
%~ |\sidehead| row should be preceded by a |\skipabovesidehead| and followed by a
%~ |\skipbelowsidehead|.

\def \sidehead #1#2{%                                   {columns}{heading} %^tabular
  \multispan{#1}%
  \leftcell{\the\sideheadfont \colortext{\the\sideheadcolor}{#2}}}

%                       Vertical Spacing
%                       -------- -------


%~ This command eliminates the inter-row space between two rows. It must be
%~ used between two consective rows of table heads. Shorthand: |@C|.

\def \closeuprows {%                                    %^tabular
  \tabvspace{-\interrowskip}}

%~ This command adds extra space between column heads and the first data row.
%~ It must be used in tables that do not have head rules.

\def \skipbelowcolhead {%                               %^tabular
  \zchkbelowhead
  \tabbbskip{\colheadbelowskip}}

%~ This command produces the appropriate vertical space above
%~ a spanner rule. Shorthand: |@S|. See also |\skipbelowspannerrule|.

\def \skipabovespannerrule {%                           %^tabular
  \tabbbskip{\spannerruleaboveskip}}

%~ This command produces the appropriate vertical space below
%~ a spanner rule. Shorthand: |@T|. See also |\skipabovespannerrule|.

\def \skipbelowspannerrule {%                           %^tabular
  \tabbbskip{\spannerrulebelowskip}}

%~ This command produces the appropriate vertical space above
%~ a side head. See also |\skipbelowsidehead|.

\def \skipabovesidehead {%                              %^tabular
  \tabbbskip{\sideheadaboveskip}}

%~ This command produces the appropriate vertical space below
%~ a side head. See also |\skiabovewsidehead|.

\def \skipbelowsidehead {%                              %^tabular
  \tabbbskip{\sideheadbelowskip}}

%~ This command produces extra vertical space so that the base-to-base space
%~ between the preceding and following rows is as specified.

\def \tabbbskip #1{%                                    {amount} %^tabular
  \ztabbbskip{#1,-,\dp\zrowstrut,-,\ht\zrowstrut}%
  \the\ztabspacerow\cr}

%~ This command produces extra vertical space between a row and a rule.
%~ It must be used instead of |\tabbbskip| to obtain the desired results when
%~ spacing above horizontal rules. See also |\tabbbskipbelowrule|.

\def \tabbbskipaboverule #1{%                           {amount} %^tabular
  \noalign{\nobreak}%
  \ztabbbskip{#1,-,\dp\zrowstrut,-,\tabruleheight}%
  \noalign{\if \zcolrulesenabled \zsuppresscolrules \fi}%
  \the\ztabspacerow \if \zcolrulesenabled \zallowcolrules \fi\cr
  \noalign{\nobreak}}

%~ This command produces extra vertical space between a rule and a row.
%~ It must be used instead of |\tabbbskip| to obtain the desired results when
%~ spacing below horizontal rules. See also |\tabbbskipaboverule|.

\def \tabbbskipbelowrule #1{%                           {amount} %^tabular
  \ztabbbskip{#1,-,\ht\zrowstrut}%
  \the\ztabspacerow\cr}

%~ This command produces the specified amount of extra vertical space
%~ between two rows of the table.

\def \tabvspace #1{%                                    {amount} %^tabular
  \noalign{%
    \zsetrowclass{\zrcvspace}%
    \zsetvspacebox{#1}}%
  \the\ztabspacerow\cr}

\def \ztabbbskip #1{%
  \noalign{%
    \zsetrowclass{\zrcbbskip}%
    \if \eqlp{\zprevrowclass}{\zrcbbskip}%
      \tdimena = 0pt\relax
    \else
      \calculate \tdimena = {#1}%
    \fi
    \zsetvspacebox{\tdimena}}}

\definebox{\ztabvspacebox}
\setbox \ztabvspacebox = \hbox{}%

\def \zsetvspacebox #1{%
  \if \dimnegp{#1}%
    \vskip #1\relax
    \dp\ztabvspacebox = 0pt
  \else
    \dp\ztabvspacebox = #1\relax
  \fi}

\def \zchkbelowhead {%
  \noalign{%
    \if \neqlp{\zprevrowclass}{\zrchead}%
      \warning{needheads}{The previous row should be a row of column heads}%
    \fi}}

%                       Horizontal Rules
%                       ---------- -----


%~ This command produces a custom version of the partial table rule
%~ (|\partialtabrule|). The color and thickness of the rules is specified
%~ explicitly.

\def \custompartialtabrule #1#2#3{%             {color}{thickness}{columns} %^tabular
  \multispan{#3}%
  \color{#1}%
  \ruleleaders{\hrule height #2 depth 0pt}%
  \endcolor}

%~ This command produces a custom version of the table spanner rule
%~ (|\spannerrule|). The color and thickness of the rules is specified
%~ explicitly.

\def \customspannerrule #1#2#3{%                {color}{thickness}{columns} %^tabular
  \multispan{#3}%
  \rowstrut
  \color{#1}%
  \ruleleaders{\hrule height #2 depth 0pt}%
  \endcolor}

%~ This command produces a custom version of the table rule
%~ (|\tabrule|). The color and thickness of the rules is specified
%~ explicitly.

\def \customtabrule #1#2{%                              {color}{thickness} %^tabular
  \multispan{\tabcolcount}%
  \color{#1}%
  \ruleleaders{\hrule height #2 depth 0pt}%
  \endcolor\cr}

%~ This command produces a table rule across the specified number of columns.
%~ It is similar to |\spannerrule| but sets a rule of the same thickness
%~ as |\tabrule|.

\def \partialtabrule #1{%                                       {columns} %^tabular
  \custompartialtabrule{\the\tabrulecolor}{\tabruleheight}{#1}}

%~ This command produces a spanner rule across the specified number of columns.
%~ The color and thickness of the rule are determined by the design. A row with
%~ spanner rules is usually preceded and followed by |\skipabovespannerrule| and
%~ |\skipbelowspannerrule|.

\def \spannerrule #1{%                                          {columns} %^tabular
  \customspannerrule{\the\spannerrulecolor}{\spannerruleheight}{#1}}

%~ This command produces the standard bottom rule in a table. Which rules are
%~ required is specified in the |\style| parameter of the |\tabular| design.
%~ This command is not followed by |\cr|.

\def \tabbottomrule {%                                          %^tabular
  \tabbbskipaboverule{\tabbottomruleaboveskip}%
  \tabrule}

%~ This command produces the standard head rule in a table. Which rules are
%~ required is specified in the |\style| parameter of the |\tabular| design.
%~ This command is not followed by |\cr|.

\def \tabheadrule {%                                            %^tabular
  \zchkbelowhead
  \tabbbskipaboverule{\colheadbelowskip}%
  \tabrule
  \tabbbskipbelowrule{\tabheadrulebelowskip}}

%~ This command produces a table rule across the entire width of the table. The
%~ color and thickness of the rule are determined by the design. This command
%~ is not followed by |\cr|.

\def \tabrule {%                                                %^tabular
  \customtabrule{\the\tabrulecolor}{\tabruleheight}}

%~ This command produces the standard top rule in a table. Which rules are
%~ required is specified in the |\style| parameter of the |\tabular| design.
%~ This command is not followed by |\cr|.

\def \tabtoprule {%                                             %^tabular
  \tabrule
  \noalign{\nobreak}%
  \tabbbskipbelowrule{\tabtoprulebelowskip}}

%                       Vertical Rules
%                       -------- -----


%~ This command is used in the normally empty cell corresponding to a vertical
%~ rule column. It adjusts the width, height, and/or depth of the rule in that
%~ cell. To adjust one of those dimensions, specify the new dimension in
%~ points, without the usual |pt|, in the appropriate argument position.
%~ Omitted dimensions will have their standard values. You must specify both
%~ commas and the semicolon. Shorthand: |@A*width*,*height*,*depth*;|

\def \adjustcolrule #1,#2,#3;{%                         width,height,depth; %^tabular
  \if \notp{\emptyargp{#1}}width #1pt\fi
  \if \notp{\emptyargp{#2}}height #2pt\fi
  \if \notp{\emptyargp{#3}}depth #3pt\fi\relax}

%~ This command can be used between rows of a table to allow all vertical
%~ rules. This is typically done after the column head portion of a table. If
%~ |\allowcolrules| appears just before |\tabheadrule|, it is deferred until
%~ after the vertical space above the horizontal rule, so that the vertical
%~ rules recommence precisely at the horizontal rule. See also
%~ |\suppresscolrules|.

\def \allowcolrules {%                                  %^tabular
  \noalign{%
    \zallowcolrules
    \global\setflag \zcolrulesenabled = \true}}

\def \zallowcolrules {%
  \gdef \zcolrulegate {}}

%~ This command can be used between rows of a table to suppress all vertical
%~ rules. This is typically done for the column head portion of a table.
%~ See also |\allowcolrules|.

\def \suppresscolrules {%                               %^tabular
  \noalign{\zsuppresscolrules}}

\def \zsuppresscolrules {%
  \gdef \zcolrulegate {\nocolrule}}

%~ This command is used in the normally empty cell corresponding to a vertical
%~ rule column. It suppresses the vertical rule in that cell. Shorthand: |@N|.

\def \nocolrule {%                                      %^tabular
  width 0pt }

%                       Inter-Row Facilities
%                       --------- ----------


%~ This command can be used between rows of a table to insert vertical material
%~ that is independent of the rows themselves. It is rarely needed.

\def \adjusttabular #1{%                                {commands} %^tabular
  \noalign{#1}}

\let \adjusttab = \adjusttabular

%                       Low-Level Alignment Facilities
%                       --------- --------- ----------


\let \completerow = \cr

\def \ialign {\everycr = {}\tabskip=0pt \halign}

\def \oalign #1{%                                       {row...}
  \ensurepar
  \vtop{\baselineskip = 0pt
        \lineskip = .25ex
        \ialign{##\cr #1\crcr}}}

\def \ooalign {%
  \lineskiplimit = -\maxdimen
  \oalign}

\def \ozalign {%
  \lineskiplimit = 0pt\relax
  \oalign}