\input blue.tex \loadindexmacros \report \hfuzz15pt \bluechapter Tabular Material \beginsummary BLUe's format provides btable for the class of (simple) bordered tables. It will be shown that this model can be used to format a wide variety of tables. Difference in representation can be obtained via attributes, i.e., without changing the markup. Customization of the macro can be done by modification of the separators for the caption, the columns, and the like. The diversity of tabular material in general has been illustrated by a kaleidoscope of tables borrowed from literature. For the latter group the markup is not necessarily restricted to btable or halign. The example of how Knuth marked up real-life tables is illustrated by his font charts. \endsummary The backbone of \bluetex's tables is |\btable|, to format a bordered table. Other \TeX niques for formatting tables will be dealt with too. The formatting of tables with simultaneous row and column spans is a subject for the `educated layman,' not for the faint-hearted. \bluehead Bordered table A bordered table consists of a caption, a header, row stubs, a table proper, and a footer, all with parameterized separators. Special cases occur when some of the elements are absent. Abstraction from a ruled and a non-ruled table is realized at the user level. Ruled can be specified either as horizontal, vertical or both. Dotted rules, also the partial ones, can be specified. No variation in the line thicknesss has been coded. Framing has been treated just as if a general document element has to be framed. I chose to leave the caption and the footer outside the frame.\ftn{However, we can frame any document element, can't we?} The positioning of the elements can be specified as centered, flushed left, or flushed right. A ^{template} is provided by default. Caption, border (first, header, row stubs), and footer can be specified; all mutual orthogonal and independent of \cs{data}. ^^{bordered table model} \bluesubhead Model {\def\btablecaption{$\leftarrow$\hfill C a p t i o n\hfill$\rightarrow$} \def\first{\hbox to6ex{\hss First\hss}} \def\header{\hbox to18ex{\hss Header\hss}} \def\rowstblst{{\hfil$\vcenter to20ex{\vss\offinterlineskip \fifo rowstblst\ofif\vss}$}} \def\data{$\vcenter{\offinterlineskip\hbox{Table}\kern1ex\hbox{Proper}}$} \def\footer{$\leftarrow$\hfill{\small F o o t e r}\hfill\hfill\hfill$\rightarrow$} \def\fifo#1{\ifx\ofif#1\ofif\fi\process{#1}\fifo}\def\ofif#1\fifo{\fi} \def\process#1{\hbox to0pt{\hss#1\hss}\kern.5ex} \nonframed $$\vcenter{\btable\data}$$ }%end scope \TeX nically caption and footer are \cs{hbox}-es and table proper is an \cs{vbox}. The separators of caption and footer are default \cs{medskip} and \cs{smallskip}. \bluesubhead Markup tags \bitem tags ^|\beginbtable| and |\endbtable|, or the shortcut |\btable|, and the column and row separator ^|\cs|, and ^|\rs| \bitem defs to be redefined ^|\btablecaption|, ^|\first|, ^|\header|, ^|\footer|, ^|\rowstblst|, (all defined empty by default) \bitem table markup tags, ^|\logms|, ^{logical multispan} to span a number of {\em logical\/} columns \bitem attributes \itemitem{--} ^|\ruled|, ^|\hruled|, ^|\vruled|, ^|\dotruled| \hfill Default:\hbox to13ex{\hfil^|\nonruled|} \itemitem- ^|\framed|, ^|\dotframed| \hfill Default:\hbox to13ex{\hfil^|\nonframed|} \itemitem- ^|\fll| (flushed left), ^|\flr| (flushed right) \hfill Default:\hbox to13ex{\hfil^|\ctr|} \bitem token variables ^|\prebtable|, ^|\postbtable| for positioning the table within the context.{\parindent0pt\ftn{In practice the math display is used most of the time.}} \smallbreak By the way the above model is an example of the markup of a bordered table.\ftn{Admittedly a little complicated. Simpler examples will follow.} The markup reads as follows. \beginverbatim \def\btablecaption{$\leftarrow$\hfill C a p t i o n\hfill$\rightarrow$} \def\first{\hbox to6ex{\hss First\hss}} \def\header{\hbox to18ex{\hss Header\hss}} \def\rowstblst{{\hfil$\vcenter to20ex{\vss\offinterlineskip \fifo rowstblst\ofif\vss}$}} \def\process#1{\hbox to0pt{\hss#1\hss}\kern.5ex} \def\data{$\vcenter{\offinterlineskip\hbox{Table}\kern1ex\hbox{Proper}}$} \def\footer{$\leftarrow$\hfill{\small F o o t e r}\hfill\hfill\hfill $\rightarrow$} $$\vcenter{\btable\data}$$ !endverbatim \thissubhead{\runintrue} \bluesubhead Customization\par \cs{$\langle X\rangle$sep} are parameters, which govern the kind of ^{separators}. The following are defaults to be customized. \beginverbatim \def\cellsize{\cvsize=4ex\tsht=.775\cvsize\tsdp=.225\cvsize} \def\colsepsurround{\kern.5em}\def\captionsep{\medskip}\def\rowstbsep{\vrule} \def\headersep{\hrule}\def\footersep{\smallskip}\def\template{} !endverbatim The positioning of the elements in the cells is parameterized by \cs{lft} and \cs{rgt}. They are equal to \cs{hfil} by default. A nice application is to make these equal to \$ in such a way that data can be processed in math mode. The empty template looks curious. The explanation is: when empty\Dash i.e., a user did not provide one\Dash a standard template will be used. \vfill\eject \bluehead Use of btable macro There are some pitfalls that I know of and that a user might like to be aware of. ^^{btable, pitfalls} \bitem When \cs{header}, \cs{footer} and the like are defined they keep their value. So when you don't have a header in the next table, be sure that this definition is empty. \bitem Most of the time I used definitions with \cs{btable} instead of token variables. Beware. \bitem To specify the row stub list separately from the data might yield a first column and a data part of unequal size. \bitem The ^|\cs| is ambiguous. In \bluetex{} it has the function to yield the argument as control sequence, while within btable the meaning is the column separator. \bitem When verbatims are also part of the data process the table on the fly via \cs{beginbtable} \dots\thinspace \cs{endbtable}. However, there is a problem when the header and footer have to be processed on the fly too. \bitem In the markup of the table in the appendix `History of Changes,' the problems are the right line distances in a \cs{vtop}. The latter as element in the table. It is caused by the \cs{tstrut}, table strut, which is inserted at the end of each table row. See the script how to circumvent this problem. \bitem The attribute \cs{dotruled} is not so general as \cs{ruled} or \cs{vruled}, because we lack the primitive \cs{vdotfill} as a dotted alternative for \cs{vrule}. For horizontal rules \TeX{} provides the primitives \cs{hrule} with the dotted variant \cs{dotfill}. \smallbreak In the examples of use below the invocation of \cs{data} could have been hidden. However, in order to remain compatible with the situation where a user wishes to forget about \cs{data} and provide the table entries directly as argument to \cs{btable}, I refrained from that. \blueexample Just data, magic squares $$\def\data{2\cs7\cs6\rs 9\cs5\cs1\rs 4\cs3\cs8} \vcenter{\framed\ruled\btable\data}\qquad\qquad\qquad \def\data{16\cs 3\cs 2\cs13\rs 5\cs 10\cs 11\cs 8\rs 9\cs 6\cs 7\cs12\rs 4\cs 15\cs 14\cs 1} \def\template{\colsepsurround\lft{\oldstyle##}\rgt &&\lft##\rgt&\lft{\oldstyle##}\rgt\cr} \ruled\framed\setbox0=\btable\data%for measuring sizes \vcenter{\dotruled\dotframed\btable\data}\qquad$$ via \begincenterverbatim $$\def\data{2\cs7\cs6\rs 9\cs5\cs1\rs 4\cs3\cs8} \vcenter{\framed\ruled\btable\data}\qquad\qquad\qquad \def\data{16\cs 3\cs 2\cs13\rs 5\cs 10\cs 11\cs 8\rs 9\cs 6\cs 7\cs12\rs 4\cs 15\cs 14\cs 1} \def\template{\colsepsurround\lft{\oldstyle##}\rgt &&\lft##\rgt&\lft{\oldstyle##}\rgt\cr} \ruled\framed\setbox0=\btable\data%for measuring sizes \vcenter{\dotruled\dotframed\btable\data}\qquad$$ !endcenterverbatim Remark. To introduce the ^|\oldstyle| elegantly I added a template for the ^|\halign|. For doing this, awareness of the physical columns is needed. Logically we are talking about a {\oldstyle3}${*}${\oldstyle3} and {\oldstyle4}${*}${\oldstyle4} table. Note that for dotted variants much more work has to be done. \blueexample Data plus header, \TB{} {\oldstyle246} ^^{data with header} $$\def\header{\hfill Year\hfill\cs \hfill World Population\hfill} \def\data{8000 B.C.\cs 5,000,000\rs 50 A.D.\cs200,000,000} \flr\nonframed\vruled\vcenter{\btable\data}\qquad \ruled\vcenter{\framed\btable\data}$$ via the nearly descriptive markup \beginverbatim \def\header{\hfill Year\hfill\cs \hfill World Population\hfill} \def\data{8000 B.C.\cs 5,000,000\rs 50 A.D.\cs200,000,000} $$\flr\vruled\vcenter{\btable\data}\qquad\ruled\framed\vcenter{\btable\data}$$ !endverbatim \exercise How come that the left table contains a \cs{hrule}? \answer The header separator is not influenced by the ruled attributes. \blueexample Data with row stubs, \TB{} {\oldstyle232} ^^{data with row stubs} \nonruled\nonframed\ctr%defaults \begindemo \def\rowstblst{{Horizontal lists} {Vertical lists}{Math lists}} \def\rowstbsep{}%Customization \def\data{Chapter 14\rs Chapter 15\rs Chapter 17} $$\btable\data$$ !yields \def\rowstblst{{Horizontal lists} {Vertical lists} {Math lists}} \def\rowstbsep{} \def\data{Chapter 14\rs Chapter 15\rs Chapter 17} \btable\data \enddemo \exercise How can we obtain the same table without the use of \cs{rowstblst}? \answer Just consider all as data. \beginverbatim Alternative \def\data{Horizontal lists \cs Chapter 14\rs Vertical lists\hfill\cs Chapter 15\rs Math lists\hfill \cs Chapter 16} $$\btable\data$$ !endverbatim %end exercise \blueexample Data, row stubs, header, caption and footer ^^{data with header, row stubs, caption and footer} \nonruled\nonframed $$\def\data{11\cs12\rs 21\cs22} \vcenter{\framed\btable\data} \qquad \def\header{\logms2\hfill Header\hfill} \def\rowstblst{{$1^{st}$ row} {$2^{nd}$ row}} \vcenter{\btable\data} \qquad \def\btablecaption{Caption} \def\footer{Footer} \vcenter{\dotruled\btable\data} \qquad \vcenter{\ruled\framed\btable\data} $$ after data definition, |\def\data| |{11\cs12\rs| |21\cs22}|, via\ftn{Note the invariance of the {\tt\char92data} specification.} \begincenterverbatim $$\vcenter{\framed\btable\data} \qquad \def\header{\logms2\hfill Header\hfill} \def\rowstblst{{$1^{st}$ row} {$2^{nd}$ row}} \vcenter{\btable\data} \qquad \def\btablecaption{Caption} \def\footer{Footer} \vcenter{\dotruled\btable\data} \qquad \vcenter{\ruled\framed\btable\data}$$ !endcenterverbatim The above example shows in a nutshell the essential possibilities of the \cs{btable} macro. It is my favorite, although other nice and powerful examples are still to come. \blueexample Walter's spreadsheet, \TB{} {\oldstyle244} No preamble has to be defined. ^^{spreadsheet} $$ \def\data{1\cs\logms2Adjusted gross income \dotfill\cs \$4,000\rs 2\cs Zero bracket amount for \rs \cs a single individual \dotfill\cs\hfill\$2,300\cs \rs 3\cs Earned income \dotfill\cs \hfill\underbar{ 1,500}\cs \rs 4\cs\logms2Substract line 3 from line 2 \dotfill\cs\hfill\underbar{ 800}\rs 5\cs Add lines 1 and 4. Enter here \rs \cs\logms2and on Form 1040, line 35 \dotfill\cs\$4,800} \def\colsepsurround{\kern.5ex}\cvsize=3ex \fll\btable\data $$ The above is marked up, as a 4-column table, via \beginverbatim \def\data{1\cs\logms2Adjusted gross income \dotfill\cs \$4,000\rs 2\cs Zero bracket amount for \rs \cs a single individual \dotfill\cs\hfill\$2,300\cs \rs 3\cs Earned income \dotfill\cs \hfill\underbar{ 1,500}\cs \rs 4\cs\logms2Substract line 3 from line 2 \dotfill\cs\hfill\underbar{ 800}\rs 5\cs Add lines 1 and 4. Enter here \rs \cs\logms2and on Form 1040, line 35 \dotfill\cs\$4,800} \def\colsepsurround{\kern.5ex}\cvsize=3ex $$\fll\btable\data$$ !endverbatim \blueexample Spreadsheet digression It happens that tables\Dash read budgets\Dash set by \AllTeX{} suffer from a simple addition flaw. Can't we add a {\em little\/} spreadsheet functionality to \TeX, i.e., let \TeX{} do the additions?\ftn{Courtesy Phil Taylor's Trigonometry \TeX, for the idea to use dimen vars and how to remove the pt. Remember that \TeX{} allows {\oldstyle16} bit fixed-point arithmetic. It is limited to absolute values $<$ {\oldstyle16384}.} \begingroup \newdimen\a\newdimen\b\newdimen\c \begindemo \def\data{r1\cs \ass\a{1.23} \rs r2\cs\ubp{\ass\b{4.56}}\rs \cs\cs\sumup{\a\b}\global\c\dimen0\rs \cs\cs\ubm{\ass\a{3.14}}\rs \cs\cs\minus\c\a} $$\btable\data$$ !yields \def\ass#1#2{\global#1=#2pt#2} \def\sumup#1{\global\dimen0=0pt \let\process\processsum\fifo#1\ofif} \def\processsum#1{\global\advance\dimen0#1\relax} \def\ofif#1\fifo{\fi\nodim\the\dimen0} \def\minus#1#2{\global \dimen0#1\global\advance\dimen0-#2 \nodim\the\dimen0} %\nodim, i.e. \xs, strips pt from % dimension quantity {\catcode`\p=12 \catcode`\t=12 \gdef\xs#1pt{#1}} \def\nodim{\expandafter\xs} %\underbar extended by + and - \def\ubp#1{\underbar{#1}\rlap {\lower.8ex\hbox{\thinspace\small$+$}}} \def\ubm#1{\underbar{#1}\rlap {\lower.8ex\hbox{\thinspace\small$-$}}} % \def\data{r1 \cs \ass\a{1.23} \rs r2 \cs\ubp{\ass\b{4.56}}\rs \cs\cs\sumup{\a\b}\global\c\dimen0\rs \cs\cs\ubm{\ass\a{3.14}}\rs \cs\cs\minus\c\a} $$\btable\data$$ \enddemo \endgroup with auxiliaries \beginverbatim \newdimen\a\newdimen\b\newdimen\c \def\ass#1#2{\global#1=#2pt#2} \def\sumup#1{\global\dimen0=0pt\let\process\processsum\fifo#1\ofif} \def\processsum#1{\global\advance\dimen0#1\relax} \def\ofif#1\fifo{\fi\nodim\the\dimen0} \def\minus#1#2{\global\dimen0#1\global\advance\dimen0-#2\nodim\the\dimen0} %\nodim, i.e. \xs, strips pt from % dimension quantity {\catcode`\p=12 \catcode`\t=12 \gdef\xs#1pt{#1}} \def\nodim{\expandafter\xs} %\underbar extended by + and - \def\ubp#1{\underbar{#1}\rlap{\lower.8ex\hbox{\thinspace\small$+$}}} \def\ubm#1{\underbar{#1}\rlap{\lower.8ex\hbox{\thinspace\small$-$}}} !endverbatim \blueexample Part of AAP's table, AAP {\oldstyle1989} Subtle is the header part and the alignments on the signs. ^^{AAP table} \def\nl{\hfil\strut\break\strut} {% \catcode`?=\active \def?{\kern1.1ex} % \def\btablecaption{AAP's table:\qquad Job Changes 1973--1980\hfill} \def\rowstblst{{Texas}{Maryland}} \def\header{\copy1\cs\copy2\cs\copy3} \setbox1=\vtop{\noindent\hsize14ex Gain/Loss of\nl hospitals \nl since 1973} \setbox2=\vtop{\noindent\hsize13ex Total No\nl of CEO Job\nl Changes\nl 1973--90\strut} \setbox3=\vtop{\noindent\hsize10ex Survival\nl Rate of\nl CEO's} \def\data{$+20$\cs---\cs22\%\rs $+?5$\cs 42\cs24\%} \def\footer{Source: David Kinzer, `Turnover etc.} $$\btable\data$$ }obtained via \beginverbatim \def\btablecaption{AAP's table:\qquad Job Changes 1973--1980\hfill} \def\rowstblst{{Texas}{Maryland}} \def\header{\copy1\cs\copy2\cs\copy3} \def\data{$+20$\cs---\cs22\%\rs $+?5$\cs 42\cs24\%} \def\footer{Source: David Kinzer, `Turnover etc.} $$\btable\data$$ !endverbatim with auxiliaries \beginverbatim \def\nl{\hfil\strut\break\strut} \catcode`?=\active \def?{\kern1.1ex} \setbox1=\vtop{\noindent\hsize14ex Gain/Loss of\nl hospitals \nl since 1973} \setbox2=\vtop{\noindent\hsize13ex Total No\nl of CEO Job\nl Changes\nl 1973--90} \setbox3=\vtop{\noindent\hsize10ex Survival\nl Rate of\nl CEO's} !endverbatim Remark. With longer footnotes put the text in a \cs{vtop}, with \cs{hsize} set to \cs{thsize}.\ftn{The table proper is first set in a box, and this box is measured yielding \cs{thsize} and \cs{tvsize}. After this the \cs{header} and \cs{footer} are set using the \cs{thsize}.} \blueexample AT\&T table diversions, \TB{} {\oldstyle247} Subtle is the alignment on the dot via the use of `?', \`a la Knuth, and the |\llap\$|, and |\rlap*|. ^^{ATT table} \def\rowstblst{} {\def\btablecaption{AT\&T Common Stock\hfill} \def\header{Year\cs Price\cs Dividend} \catcode`?=\active \def?{\kern1.1ex} \def\data{1971\cs41--54\cs\llap\$2.60\rs 2\cs41--54\cs 2.70\rs 3\cs46--55\cs 2.87\rs 4\cs40--53\cs 3.24\rs 5\cs45--52\cs 3.40\rs 6\cs51--59\cs ?.95\rlap*} \def\footer{* (first quarter only)} $$\framed\vcenter{\vbox{\small\btable\data}}\qquad\qquad \def\btablecaption{} \def\header{\logms3 \hfil AT\&T Common Stock\hfil\rs \hfill Year\hfill\cs\hfill Price\hfill\cs \hfill Dividend\hfill} \vcenter{\flr\ruled\btable\data}$$ } via \begincenterverbatim \def\btablecaption{AT\&T Common Stock} \def\header{Year\cs Price\cs Dividend} \catcode`?=\active \def?{\kern1.1ex} \def\data{1971\cs41--54\cs\llap\$2.60\rs 2\cs41--54\cs 2.70\rs 3\cs46--55\cs 2.87\rs 4\cs40--53\cs 3.24\rs 5\cs45--52\cs 3.40\rs 6\cs51--59\cs ?.95\rlap*} \def\footer{* (first quarter only)} $$\framed\vcenter{\vbox{\small \btable\data}}\qquad\qquad % \def\btablecaption{} \def\header{\logms3 \hfil AT\&T Common Stock\hfil\rs \hfill Year\hfill\cs \hfill Price\hfill\cs \hfill Dividend\hfill} \vcenter{\flr\ruled\btable\data}$$ !endcenterverbatim \blueexample Pittman's deterministic multiplication table Typographically and in other programming languages a trifle. In \TeX\ the coding matters. ^^{multiplication table} \def\header{} \def\rowstblst{} \def\btablecaption{}\def\first{}\def\footer{} \newcount\rcnt \newcount\ccnt \newcount\tnum \newcount\mrow \newcount\mcol \rcnt1 \ccnt1 \def\rows{\global\ccnt1 \cols \global\advance\rcnt1 \ifnum\rcnt>\mrow\swor\fi\rs\rows} \def\swor#1\rows{\global\rcnt1 \global\ccnt1 \fi} \def\cols{\tnum\rcnt \multiply\tnum\ccnt \the\tnum \global\advance\ccnt1 \ifnum\ccnt>\mcol\sloc\fi\cs\cols} \def\sloc#1\cols{\fi} % \mrow2 \mcol3 $$\nonruled\nonframed \vcenter{\btable\rows}\qquad\qquad \def\first{$\times$} \def\header{\row} \def\row{\the\ccnt\global\advance\ccnt1 \ifnum\ccnt>\mcol\wor\fi\cs\row} \def\wor#1\row{\fi} \def\rowstblst{{Anything, non-empty}} \def\nxtrs{\the\rcnt\rss} \vcenter{\btable\rows}\qquad\qquad % \mrow3 \mcol4 \def\rowstblst{{Anything, non-empty}} \framed\vcenter{\btable\rows} $$ via \beginverbatim \newcount\rcnt\newcount\ccnt\newcount\tnum\newcount\mrow\newcount\mcol \rcnt1 \ccnt1 \mrow2 \mcol3 \def\rows{\global\ccnt1 \cols \global\advance\rcnt1 \ifnum\rcnt>\mrow\swor\fi\rs\rows} \def\swor#1\rows{\global\rcnt1 \global\ccnt1 \fi} \def\cols{\tnum\rcnt\multiply\tnum\ccnt\the\tnum\global\advance\ccnt1 \ifnum\ccnt>\mcol\sloc\fi\cs\cols} \def\sloc#1\cols{\fi} $$\mrow2 \mcol3 \vcenter{\btable\rows}\qquad\qquad % \def\first{$\times$} \def\header{\row} \def\row{\the\ccnt\global\advance\ccnt1 \ifnum\ccnt>\mcol\wor\fi\cs\row} \def\wor#1\row{\fi} %\def\rowstblst{{1}{2}}%Fully automated via the two defs \def\rowstblst{{Anything, non-empty}} \def\nxtrs{\the\rcnt\rss} \vcenter{\btable\rows}\qquad\qquad % \mrow3 \mcol4 %\def\rowstblst{{1}{2}{3}}%Fully automated via the two defs \def\rowstblst{{Anything, non-empty}} \def\nxtrs{\the\rcnt\rss} \framed\vcenter{\btable\rows}$$ !endverbatim %Back to defaults \def\header{}\def\rowstblst{}\def\btablecaption{}\def\first{}\def\footer{} \vfill\eject \bluehead Kaleidoscope Some examples of special tables are given in order to illustrate the diversity. The markup is not restricted to the use of \cs{btable}. With respect to programming, the deterministic tables and the tables which update the computer memory, deserve special attention. The latter category is induced by {\em computer\/} typography. \blueexample Young tableaux, irregular shape, Knuth {\oldstyle1973} ^^{Young tableaux} \begindemo \newdimen\csize\csize=3ex \newcount\cnt \def\young#1{\hbox{\vrule\vtop{\hrule \offinterlineskip\halign{&\vbox {\hbox to\csize{\strut\hss##\hss \vrule}\hrule}\cr%template #1\crcr}}}}%end \young \catcode`'=13\relax \def'{\global\advance\cnt1 \the\cnt} \def\data{'&'&'&'\cr'&'&'\cr'} \young\data \def\data{7&8&9&10\cr9&11\cr16\cr} \young\data !yields \newdimen\csize\csize=3ex \newcount\cnt \def\young#1{\hbox{\vrule\vtop{\hrule \offinterlineskip\halign{&\vbox {\hbox to\csize{\strut\hss##\hss \vrule}\hrule}\cr%template #1\crcr}}}}%end \young \catcode`'=13\relax \def'{\global\advance\cnt1 \the\cnt} \def\data{'&'&'&'\cr'&'&'\cr'} \leavevmode\qquad\young\data\qquad \def\data{7&8&9&10\cr9&11\cr16\cr} \young\data \enddemo \blueexample Pascal triangle, a deterministic table ^^{Pascal triangle} \begindemo $$\displaylines{1\cr 1\quad1\cr 1\quad2\quad1\cr 1\quad3\quad3\quad1\cr}$$ !yields\hsize=10em $$\displaylines{1\cr 1\quad1\cr 1\quad2\quad1\cr 1\quad3\quad3\quad1\cr}$$ \enddemo \exercise The Pascal triangle is deterministic. Write a macro |\def\pascal#1{...}| which provides the table with the order as argument. \answer The macro and auxiliaries read as follows. \thisverbatim{\unmc} \beginverbatim \newcount\n \newcount\rcnt \newcount\ccnt \newcount\tentry\newcount\prev % \def\pascal#1{\n#1 \def\0{1} \ccnt1 \loop\ea\xdef\csname\the\ccnt\endcsname{0} \ifnum\ccnt<\n \advance\ccnt1 \repeat\rcnt0 \ccnt0 \displaylines{\rows}} % \def\rows{\global\advance\rcnt1 \ifnum\rcnt>\n \swor\fi \nxtrow\rows} % \def\swor#1\rows{\fi} % \def\nxtrow{1 \ccnt1 \prev1 \loop\ifnum\ccnt<\rcnt \tentry\prev \prev\csname\the\ccnt\endcsname \advance\tentry\prev \ea\xdef\csname\the\ccnt\endcsname{\the\tentry} \quad\the\tentry \advance\ccnt1 \repeat\cr} !endverbatim %above blank line terminates answer. \blueexample Tower of Hanoi, deterministic The process of replacement of the disks will be printed by the invocation of |\hanoi|, $n$ an integer. No user markup is needed. ^^{tower\ of\ Hanoi} \begindemo \hanoi2 %or \beginhanoi2\endhanoi !yields \hanoi2 \enddemo \blueexample Chart, \TB{} ex{\oldstyle22}.{\oldstyle14} {\oldstyle248} ^^{chart}%but elaborated differently. {\small \newdimen\dist \dist=2\baselineskip \def\ent#1{\hbox{\vbox to 0pt {\vss\hbox to10ex{\quad\strut#1\hss} \hrule}}} \def\vl#1{\hbox{\vrule height#1\dist depth0pt}}%Vertical Line of prop. size \def\bl#1{\kern#1\dist}%BLank of prop. size %Balanced $$\offinterlineskip \vcenter{\ent{abc}} \vcenter{\ent{de} \vl2 \ent{fg}} \vcenter{\ent{hij} \vl1 \ent{klm} \bl1 \ent{nop} \vl1 \ent{qrs}} \quad%Nearly balanced tree; pruning a branch \vcenter{\ent{abc}} \vcenter{\ent{de} \vl2 \ent{fg}} \vcenter{\ent{hij} \vl{.5} %\bl{.5}<-| % \ent{klm} | \bl{1.5}% <-| \ent{nop} \vl1 \ent{qrs}}$$ }%end scope via the following alternative code without \cs{halign} \begincenterverbatim \newdimen\dist \dist=2\baselineskip \def\ent#1{\hbox{\vbox to0pt{\vss\hbox to10ex{\quad \strut#1\hss}\hrule}}} \def\vl#1{\hbox{\vrule height#1\dist depth0pt}} \def\bl#1{\kern#1\dist}%BLank of proper size %Balanced $$\offinterlineskip \vcenter{\ent{abc}} \vcenter{\ent{de} \vl2\ent{fg}} \vcenter{\ent{hij}\vl1\ent{klm}\bl1\ent{nop}\vl1\ent{qrs}} \quad%Nearly balanced tree; pruning a branch \vcenter{\ent{abc}} \vcenter{\ent{de} \vl2\ent{fg}} \vcenter{\ent{hij}\vl{.5}%\bl{.5}\ent{klm} \bl{1.5}\ent{nop}\vl1\ent{qrs}}$$ !endcenterverbatim \blueexample Binary tree The nodes are identified via Dewey's decimal notation, similar to a ToC in a book. For example, node {\oldstyle11} is the left most node at the first level. The user must supply within the environment ^|\beginbintree| \cs{endbintree} the pairs of node numbers and node contents, with at the end the level of the tree. A node which is not specified will not show. The syntax of the invocation reads \begincenterverbatim \beginbintree ... \endbintree !endcenterverbatim $$\thisbintree{\tophns13ex} \beginbintree{00}1{11}6{12}7{21}2{22}3{23}4 2\endbintree \raise13ex\hbox{$\buildrel heap\over \longrightarrow$} \thisbintree{\tophns13ex} \beginbintree{00}7{11}6{12}4{21}3{22}2{23}1 2\endbintree $$ \begincenterverbatim $$\thisbintree{\tophns13ex} \beginbintree{00}1{11}6{12}7{21}2{22}3{23}4 2\endbintree \raise13ex\hbox{$\buildrel heap\over \longrightarrow$} \thisbintree{\tophns13ex} \beginbintree{00}7{11}6{12}4{21}3{22}2{23}1 2\endbintree $$ !endcenterverbatim \blueexample Dewey's decimal notation $$\beginbintree{00}{$root$} {11}{$n_{11}$} {12}{$n_{12}$} {21}{$n_{21}$} {22}{$n_{22}$} {23}{$n_{23}$} {24}{$n_{24}$} {35}{$n_{35}$} {36}{$n_{36}$} {49}{$n_{49}$} {410}{$n_{410}$} 4\endbintree$$ \vskip-2.5\bigskipamount \begincenterverbatim $$\beginbintree{00}{$root$} {11}{$n_{11}$}{12}{$n_{12}$} {21}{$n_{21}$}{22}{$n_{22}$}{23}{$n_{23}$}{24}{$n_{24}$} {35}{$n_{35}$}{36}{$n_{36}$} {49}{$n_{49}$}{410}{$n_{410}$} 4\endbintree$$ !endcenterverbatim \blueexample Bitstreams as names of nodes ^^|\beginbt|\thisbt{\xoffset{-400}}%Interactive binary tree traversal \beginbt 1 NTG member? 10 Plain TeX ie? 100 Honoured? 1000 cgl 1001 HH 101 On board? 1010 Chair? 10100 Erik 10101 Secretary? 101010 Gerard 101011 Treasurer? 1010110 Wietse 1010111 Dark? 10101110 JLB 10101111 FG 1011 Anonymous 11 Just a friend 8 \endbt The above b(inary)t(ree)\ftn{Courtesy Bernd Raichle.} is not foolproof and suffers from overprinting of the leaves with a tree of depth {\oldstyle10} or so. Note that the specification of the nodes is on a line by line basis\Dash \cs{obeylines} is on\Dash and that each node and its contents is separated by a space. The last line must contain the number of levels\Dash used to create the niche for the tree\Dash and the closing tag \cs{endbt}, again separated by a space. By adopting these conventions no curly braces were needed.\ftn{The above ideas emerged from an interactive traversal of a binary tree in a guess who-is-who game. The programming is such that it can be extended easily to a trinary or higher-order tree. The overprinting drawback remains, however. Alexander Calder might have appreciated these `mobiles,' \winksmiley.} \begincenterverbatim \thisbt{\xoffset{-400}} \beginbt 1 NTG member? 10 Plain TeX ie? 100 Honoured? 1000 Kees 1001 HH 101 On board? 1010 Chair? 10100 Erik 10101 Secretary? 101010 Gerard 101011 Treasurer? 1010110 Wietse 1010111 Dark? 10101110 JLB 10101111 FG 1011 Anonymous 11 Just a friend 8 \endbt \bye !endcenterverbatim There are some special tree packages. Gurari is strong with respect to diagrams in general and trees in particular. \blueexample Maze %Labyrinth via TeX, just an experiment feb 92. %Assumed is a closed rule on top and to the right %| and _ denote the rules to mark the labyrinth %Labyrinth proper \thisverbatim{\catcode`\|=12 } ^^{maze} \begindemo \catcode`|=13 \def|{\vrule} \catcode`_=13 \def_{\hrulefill} $$\vcenter{\hbox{\vtop{\hrule \offinterlineskip \halign{&\hbox to\csize{\vrule height\csize width0pt#\hfil}\cr |&_&|_& \cr &|&_& \cr |&|_&_&|\cr |_& &_&_\cr}%end \halign }\vrule%end \vbox }%end \hbox !yields \newdimen\csize \csize=3ex \catcode`|=13 \def|{\vrule} \catcode`_=13 \def_{\hrulefill} \qquad\hbox{\vtop{\offinterlineskip \hrule\halign{&\hbox to\csize {\vrule height\csize width0pt #\hfil}\cr |&_&|_& \cr &|&_& \cr |&|_&_&|\cr |_& &_&_\cr}%end \halign }\vrule%end \vbox }%end \hbox \enddemo \blueexample Crosswords: puzzle, clues and solution ^^{crosswords} \begincrosswords $$\bdata% P*On DEk* *n*S Edit \edata \vcenter{\sevenrm\csize=3ex\crw} \vcenter{\parindent=5ex \vtop{\hsize=21ex\obeylines Across 2 Switch mode 3 Knuth 6 Prior to \TeX}} \vcenter{\parindent=3ex \vtop{\hsize=25ex\obeylines Down 1 Public domain 2 All right 4 All comes to it 5 Atari type}} \vcenter{\fiverm\csize=3ex\sol}$$ \endcrosswords The above is obtained essentially via \begincenterverbatim \begincrosswords $$\bdata% P*On DEk* *n*S Edit \edata \vcenter{\sevenrm\csize=3ex\crw} \vcenter{\fiverm\csize=3ex\sol}$$ \endcrosswords !endcenterverbatim \blueexample Much alignment occurs in typesetting mathematics Aligned equations in display, matrices, and the complex commutative diagrams. This has been dealt with elsewhere, for example Knuth {\oldstyle1984}, and Spivak {\oldstyle1989}. Also typesetting of program texts requires vertical alignment. \blueexample Chess boards The first board has been marked up via ^|\leaders|,\ftn{Courtesy David Salomon.} horizontally and vertically. ^^{chess} The second is obtained via (a degenerate use of \winksmiley ) the crossword macro. {\newdimen\unitlength \unitlength3ex \begindemo \unitlength3ex \boxit{\vbox{\leaders \vbox{\offinterlineskip \hbox{\leaders\hbox{% \kern\unitlength \vrule width\unitlength height\unitlength }\hskip8\unitlength }\hbox{\leaders\hbox{\vrule width\unitlength height\unitlength \kern\unitlength }\hskip8\unitlength }}\vskip8\unitlength}} !yields \boxit{\vbox{\leaders \vbox{\offinterlineskip \hbox{\leaders\hbox{% \kern\unitlength \vrule width\unitlength height\unitlength }\hskip8\unitlength }\hbox{\leaders\hbox{\vrule width\unitlength height\unitlength \kern\unitlength }\hskip8\unitlength }}\vskip8\unitlength}} \enddemo} \begindemo \begincrosswords \obeyspaces\let =\space \csize=3ex \bdata% 8 * * * * 7* * * * 6 * * * * 5* * * * 4 * * * * 3* * * * 2 * * * * 1* * * * *ABCDEFGH \edata \sol \endcrosswords !yields \begincrosswords \obeyspaces\let =\space \csize=3ex \bdata% 8 * * * * 7* * * * 6 * * * * 5* * * * 4 * * * * 3* * * * 2 * * * * 1* * * * *ABCDEFGH \edata \sol \endcrosswords \enddemo \exercise How can we add field indicators on top and to the right? \answer Extend the data by the numbers at the end of each row, and copy the last row also on top. \beginverbatim \bdata% *ABCDEFGH* 8 * * * *8 7* * * * 7 6 * * * *6 5* * * * 5 4 * * * *4 3* * * * 3 2 * * * *2 1* * * * 1 *ABCDEFGH* \edata !endverbatim \exercise How can we diminish the ^{optical illusion} of the border? \answer Make the border thicker. For example via |\boxit{\boxit{\sol}}|. Why don't you develop a nice border macro? \exercise How can we add pieces to the board? \answer Chess pieces are available in a font. Similar to the letters in the solution of the crosswords we can put in pieces. For example let us assume for simplicity's sake that K denotes the white king then the following yields the requested result. \beginverbatim \begincrosswords \obeyspaces\let =\space \csize=3ex \bdata% 8 * * * * 7* * * * 6 * * * * 5* * * * 4 *K* * * 3* * * * 2 * * * * 1* * * * *ABCDEFGH \edata \boxit{\boxit{\sol}} \endcrosswords !endverbatim %blank line is needed, to close answer. The above entails that we are on the way to generate any board and just add the pieces, all based on the crosswords macro approach. \blueexample Optical illusion Again a nice application of the use of ^|\leaders|,\ftn{For \cs{soto} and and \cs{sot} see the script file.} horizontally and vertically. When I submitted my crosswords macro to \TUB{} it was refused because of the wiggling of the frame!?! There the similar effect is on with neighbouring black and white squares. The black squares look smaller than the white squares, yielding a ^{wiggling illusion}. \newdimen\unitlength \unitlength5ex \newbox\soto\setbox\soto\vbox{\hrule height1exwidth5ex\relax \hbox to5ex{\vrule width1exdepth0pt\relax \hss\vrule height3exwidth1exdepth0pt}% \hrule height1exwidth5ex\relax} {\newdimen\unitlength \unitlength5ex \newbox\sot \setbox\sot\vbox to\unitlength{\vss \hbox to\unitlength{\hss \vrule height.6\unitlength width.6\unitlength depth0pt\hss}% \vss} \smallskip \begindemo \boxit{\vbox{\leaders\vbox{% \offinterlineskip\hbox{\leaders \hbox{\copy\soto\copy\sot}% \hskip30ex}% \hbox{\leaders \hbox{\copy\sot\copy\soto}% \hskip30ex}}% \vskip30ex}} !yields \boxit{\vbox{\leaders\vbox{\offinterlineskip \hbox{\leaders\hbox{\copy\soto\copy\sot}\hskip30ex}% \hbox{\leaders\hbox{\copy\sot\copy\soto}\hskip30ex}}% \vskip30ex}} \enddemo \blueexample Soto's kinetic art \begindemo \leavevmode %background \hbox{\xleaders\hbox to.5ex{\hss \vrule height6\unitlength\hss }\hskip6\unitlength }\kern-6\unitlength %the squares \boxit{\vbox{\offinterlineskip \leaders\hbox{\leaders\copy\sot \hskip6\unitlength }\vskip6\unitlength}} !yields \leavevmode \hbox{\xleaders\hbox to.5ex{\hss \vrule height6\unitlength\relax\hss }\hskip6\unitlength}\kern-6\unitlength %the squares \boxit{\vbox{\offinterlineskip \leaders\hbox{\leaders\copy\sot \hskip6\unitlength}\vskip6\unitlength}} \enddemo } \blueexample Row and/or column spans, partial horizontal rules ^^{row\ and\ column\ spans} %Fill-in form bridge \nonruled\ctr\framed \def\rowstblst{} {\small%\defaults \newcount\bcnt \def\lines{\global\advance\bcnt by1 \ifnum\bcnt=3 et cetera\hidewidth \senil\fi\the\bcnt.\cs\cs\cs\cs\cs\cs\rs\lines} \def\senil#1\lines{\fi} \thisbtable{ \def\ghostrow{\omit\colsepsurround% \vbox to0pt{\vss\hbox to5ex{\hss Pair\hss}\vskip.5ex \hbox to5ex{\hss No\hss}\vss}\prs\logms2\lineglue\srp \vbox to0pt{\vss\hbox to5ex{\hss Re-\hss}\vskip.5ex \hbox to5ex{\hss sults\hss}\vss}\prs\logms2\lineglue\srp \vbox to0pt{\vss\hbox to15ex{\hss Game \dots\hss}\vskip1.5ex \hbox to15ex{\hss MP$\,$s\hss}\vss}\colsepsurround\cr} \def\header{\cs\logms2\hfil Contract\hfil\cs \cs\logms2\hfil Scores\hfil\cs\grs \cs N--S\cs E--W\cs\cs N--S\cs E--W\cs} } $$ \framed\ruled\btable\lines$$ }%end scope \beginverbatim \newcount\bcnt \def\lines{\global\advance\bcnt by1 \ifnum\bcnt=3 et cetera\hidewidth \senil\fi\the\bcnt.\cs\cs\cs\cs\cs\cs\rs\lines} \def\senil#1\lines{\fi} \thisbtable{ \def\ghostrow{\omit\colsepsurround% \vbox to0pt{\vss\hbox to5ex{\hss Pair\hss}\vskip.5ex \hbox to5ex{\hss No\hss}\vss}\prs\logms2\lineglue\srp \vbox to0pt{\vss\hbox to5ex{\hss Re-\hss}\vskip.5ex \hbox to5ex{\hss sults\hss}\vss}\prs\logms2\lineglue\srp \vbox to0pt{\vss\hbox to15ex{\hss Game \dots\hss}\vskip1.5ex \hbox to15ex{\hss MP$\,$s\hss}\vss}\colsepsurround\cr} \def\header{\cs\logms2\hfil Contract\hfil\cs \cs\logms2\hfil Scores\hfil\cs\grs \cs N--S\cs E--W\cs\cs N--S\cs E--W\cs} } $$ \framed\ruled\btable\lines$$ !endverbatim \exercise How many rows does the header have? \answer Descriptive {\oldstyle1}, visual {\oldstyle2}, and for plain \TeX\ formatting {\oldstyle3}. It is all a matter of point of view. \exercise The above ^{recursive markup} of the data is elegant, especially when the table is large. Simplify the markup by abandoning the independence of size, i.e., provide the data explicitly instead of recursively. \answer The `data' can be defined as follows. \beginverbatim \def\data{1.\cs\cs\cs\cs\cs\cs\rs 2.\cs\cs\cs\cs\cs\cs\rs et cetera\hidewidth} !endverbatim \blueexample Bridge pair match scheme, with special `first' element $$\def\first{\thispicture{\unitlength=6ex \xdim{1.4}\ydim{1}}% \lower1.5ex\hbox\beginpicture%(1.4, 1)(0,-.1) \put( 0.0, 0.0){\small \strut Round}% \put( 1.4, 0.575){\llap{\small Game}}% \put( 1.4, 0.1){\line(-2, 1){1.4}}% \endpicture\lower2ex\null} \def\header{% 1--3 \cs 4--6 \cs 7--9 \cs 10--12\cs13--15\cs 16--18 \cs 19--21} \def\rowstblst{{1.}{2.}{et cetera}} \def\data{% 1--2 \cs \cs \cs2: 3--4\cs \cs3: 5--6 \cs4: 7--8\rs 4: 8--3\cs1: 1--6\cs \cs \cs2: 5--7 \cs \cs3: 2--4\rs %\cs \cs \cs \cs \cs \cs \rs } \framed\ruled\btable\data $$via \beginverbatim \def\first{\thispicture{\unitlength=6ex\xdim{1.4}\ydim{1}}% \lower1.5ex\hbox\beginpicture%(1.5, 1)(0,-.1) \put( 0.0, 0.0){\small \strut Round}% \put( 1.4, 0.575){\llap{\small Game}}% \put( 1.4, 0.1){\line(-2, 1){1.4}}% \endpicture \lower2ex\null } \def\header{% 1--3 \cs 4--6 \cs 7--9 \cs 10--12\cs13--15\cs 16--18 \cs 19--21} \def\rowstblst{{1.}{2.}{et cetera}} \def\data{% 1--2 \cs \cs \cs2: 3--4\cs \cs3: 5--6 \cs4: 7--8\rs 4: 8--3\cs1: 1--6\cs \cs \cs2: 5--7 \cs \cs3: 2--4\rs %\cs \cs \cs \cs \cs \cs \rs } \framed\ruled\btable\data !endverbatim Remark. The need for centering the first row is induced by \cs{first}. It is elegant to solve the problem for that in ^|\first|. \exercise How can we center the numbers in the first column? \answer Add \cs{hfil} in the \cs{rowstblst} via \beginverbatim \def\rowstblst{{\hfil1.}{\hfil2.}{et cetera}} !endverbatim Another solution is the following template \beginverbatim \def\template{\colsepsurround\hfil##\hfil&&\lft##\rgt\cr} !endverbatim \blueexample Alignment at decimal points Generally this is done by introducing an extra column for the dot, and flushing right the digits left and flushing left the digits right of it. It comes from the wish not to print non-significant leading zeroes, and to suppress zeroes behind the point for exact numbers. {\oldstyle3}.{\oldstyle5} means exactly 3${1\over2}$. {\oldstyle3}.{\oldstyle500} means accurate to three digits. I would mark up the numbers separately and insert Knuth's `?', \TB{} {\oldstyle240}\dash{\oldstyle241}, for non-signicant zeroes, automatically. The latter can also be done by programming the editor by a template consisting of sufficient ?-s followed by the decimal point. The numbers required can be brought in by overtyping the template. Related to ^{alignment at decimal point}s is ^{alignment at number sign}s,\ftn{Another column for the signs offends the structure. At a lower level one could think of {\tt\char92scs}, a Sign Column Separator, but that is not nice either.} see the AAP table. \blueexample Nested table A ruled table with unruled tables as data is incorporated in the chapter `Creating an index,' to illustrate the ordering choices. See the script. ^^{nested table} \blueexample Nested, and interrupted table with updating of memory From the user level one would say: aligned material connected by text, where the latter in the case at hand is the status of the play. For the markup see the script. \beginbridge {\small %bridge data \def\LFTINF{Puzzle} \def\RGTINF{\vtop{\hbox{6NT,} \hbox{by East}}} % \Ns={KQ76}\Es={T9}\Ss={8542}\Ws={AJ3} \Nh={J98} \Eh={A2}\Sh={QT74}\Wh={K653} \Nd={J942}\Ed={T5}\Sd={Q876}\Wd={AK3} \Nc={65}\Ec={KJ9xxxx}\Sc={2}\Wc={AQT} \showgame \LEADS\bplay h4! & hK & h8 & h2 & --& 1\LEADW\cr cA & c5 & cx & c2 & --& 2\cr cQ & c6 & cx & s2 & --& 3\cr cT & h9 & cK & s4 & --& 4\LEADE\cr cJ & s5 & s3 & s6 & --& 5\cr c9 & s8 & h5 & s7 & --& 6\cr cx & d6 & sJ & d2 & --& 7\cr \bintermezzo \def\RGTINF{\vtop{\hbox to 0pt{NS squeezed on\hss} \hbox to 0pt{\cl\ continuation?\hss} \hbox to 7ex{\hss}}} %phantom for alignment \Ec={{\ooalign{\hfil\raise.07ex% \hbox{x}\hfil\crcr\mathhexbox20D}}} \showgame \Ec={x} \eintermezzo cx & h7 & h6 & hJ & --& 8\cr \omit et cetera \hidewidth \cr \eplay }%end of scope \endbridge Tables which also require updating of memory occur with typesetting of chess, for example Tutelaers {\oldstyle1992}, or GO, Ko{\l}odziejska {\oldstyle1991}. \blueexample Fill-in forms The registration forms for the various \TeX{} conferences are captivating. Now and then I ponder about the e-mail equivalents of the traditional snail forms, especially what (and how they) should be filled in. Redefine a list of empty definitions? \blueexample Time tables Railway, bus, \dots\thinspace, and the use of rotated fonts. This is a \PS{} issue. \blueexample No markup For simple tables the data can be specified {\em without\/} \cs{cs}-s, and \cs{rs}-s, i.e., without explicit markers for column and row separators. These can be inserted by \TeX, see \TB{} {\oldstyle249}. For special cases, for example centering texts\ftn{See the implementation of \cs{center} in the file.} and crosswords, this is handy. ^^{no markup} \thissubhead{\runintrue} \bluesubhead Pondering about lists\par makes you realize that the table proper data forms a nested list with \cs{rs} and \cs{cs}, respectively first level and second level separators. One could also adopt || and {\tt\char32} for that, in other words allow natural data provision. \blueexample Simultaneous row spans Simultaneous column spans can be marked up in \cs{btable} by \cs{logms}---for logical columns, as an extension to \cs{multispan} for \cs{halign}. ^^{row\ spans} For row spans start from \cs{valign}, the transposition of \cs{halign}. A little more than the analogy of transposition is needed. From the \TeX-nl list the following example of spans over rows. \begindemo \hbox{\vrule\valign{&\hrule\vfil \noindent\hsize15ex\strut \xsp#\xsp\vfil\hrule\cr \multispan3{\hrule\vfil \vbox{\noindent\hsize15ex\strut \xsp This\\ \xsp looks\\ \xsp problematic}}\vfil \hrule& Doesn't it?\cr \noalign{\vrule} \hfill22 &%space needed \hfill12 & \hfill1943 & \hfill190 \cr}\vrule} %with auxiliary \def\xsp{\hbox{ }} !yields \def\xsp{\hbox{ }} \hbox{\vrule\valign{&\hrule\vfil \noindent\hsize15ex\strut \xsp#\xsp\vfil\hrule\cr \multispan3{\hrule\vfil \vbox{\noindent\hsize15ex\strut \xsp This\\ \xsp looks\\ \xsp problematic}}\vfil \hrule& Doesn't it?\cr \noalign{\vrule} \hfill22 &%space needed \hfill12 & \hfill1943 & \hfill190 \cr}\vrule} \enddemo As can be seen from this difficult example, we have to fall back on lower level details now and then. \exercise Modify the above towards a ^|\vtable| macro, such that we can use the attributes \cs{ruled}, \cs{vruled}, \cs{hruled}, with default \cs{nonruled}, and \cs{framed} and \cs{nonframed}.^^|\valign| \answer As a parameter I provided the \cs{hsize} of the table entries. For row spans the \cs{logms}, logical multispan, has been used, similar as for \cs{btable}. \beginverbatim \def\xsp{\hbox{ }} \def\vruled{\def\colsep{\vrule}\def\rowsep{}} \def\hruled{\def\colsep{}\def\rowsep{\hrule}} \def\ruled{\def\colsep{\vrule}\def\rowsep{\hrule}} \def\nonruled{\def\colsep{}\def\rowsep{}} \def\framed{\let\frameit\boxit} \def\nonframed{\def\frameit##1{##1}} \def\rs{&\null\rowsepsurround\rowsep\rowsepsurround&} \def\cs{\lcs\noalign{\colsep}} \def\lcs{\rowsepsurround\cr} \def\top{\null\vskip.5em} \def\bot{\vskip.5em} \def\ctr{\def\lft{\hfil}} \def\fll{\def\lft{}} \def\flr{\def\lft{\hfill}} %Macro \def\vtable#1{\frameit{\hbox{\valign{\top\noindent \hsize#1\lft##\bot &&##&\hsize#1\top\noindent\lft##\bot\cr \data}}}} %Defaults \nonframed\nonruled\ctr \def\rowsepsurround{\vskip.1ex} %Examples \def\data{1 \rs 2\rs 3\cs 4 \rs 5\rs 6\cs 314\rs271\rs \lcs} \vtable{7ex} \smallskip \def\data{\logms3{\hsize7ex\null \vfil\noindent\hfil1\hfil\vfil}\cs C\rs G\rs L\cs 22\rs12\rs1943\lcs} \ruled\vtable{7ex} \smallskip \def\data{\logms3{\hsize15ex\null \vfil\noindent\xsp This\\ \xsp looks\\ \xsp problematik\vfil}\cs O\rs A\rs G\cs 16\rs11\rs1954\lcs} \framed\ruled\vtable{5ex} !endverbatim %end answer \blueexample Macroscopic markup vtable, based on valign {%Example with macroscopic \vtable markup \def\xsp{\hbox{ }} \def\vruled{\def\colsep{\vrule}\def\rowsep{}} \def\hruled{\def\colsep{}\def\rowsep{\hrule}} \def\ruled{\def\colsep{\vrule}\def\rowsep{\hrule}} \def\nonruled{\def\colsep{}\def\rowsep{}} \def\framed{\let\frameit\boxit} \def\nonframed{\def\frameit##1{##1}} \def\rs{&\null\rowsepsurround\rowsep\rowsepsurround&} \def\cs{\lcs\noalign{\colsep}} \def\lcs{\rowsepsurround\cr} \def\top{\null\vskip.5em} \def\bot{\vskip.5em} \def\ctr{\def\lft{\hfil}} \def\fll{\def\lft{}} \def\flr{\def\lft{\hfill}} %Macro \def\vtable#1{\frameit{\hbox{\valign{\top\noindent \hsize#1\lft##\bot &&##&\hsize#1\top\noindent\lft##\bot\cr \data}}}} %Defaults \nonframed\nonruled\ctr \def\rowsepsurround{\vskip.1ex} \begindemo \def\data{\logms3{\hsize15ex \vfil\noindent\xsp This\\ \xsp looks\\ \xsp problematic \vfil}\rs\omit\hsize15ex \vfil\noindent \xsp Doesn't it?\vfil\cs O\rs A\rs G\rs 189\cs \rs 16\rs11\rs1954\lcs} \framed\ruled\vtable{5ex} !yields \def\data{\logms3{\hsize15ex \vfil\noindent\xsp This\\ \xsp looks\\ \xsp problematic \vfil}\rs \omit\hsize15ex\vfil\noindent \xsp Doesn't it?\vfil\cs O\rs A\rs G\rs \cs \rs16\rs11\rs1954\lcs} \framed\ruled\vtable{5ex} \enddemo} \blueexample Regular use vtable based on valign {\begindemo \def\vtable#1{\frameit{\hbox {\valign{\top\noindent \hsize#1\lft##\bot &&##&\hsize#1\top \noindent\lft ##\bot\cr \data}}}} \def\data{anatoly\rs andre\rs alex \cs beatrici\rs bernd\lcs} \nonframed\vtable{20ex} !yields \def\vruled{\def\colsep{\vrule}\def\rowsep{}} \def\hruled{\def\colsep{}\def\rowsep{\hrule}} \def\ruled{\def\colsep{\vrule}\def\rowsep{\hrule}} \def\nonruled{\def\colsep{}\def\rowsep{}} \def\framed{\let\frameit\boxit} \def\nonframed{\def\frameit##1{##1}} \def\rs{&\null\rowsepsurround\rowsep\rowsepsurround&} \def\cs{\lcs\noalign{\colsep}} \def\lcs{\rowsepsurround\cr} \def\top{\null\vskip.1em} \def\bot{\vskip.1em} \def\ctr{\def\lft{\hfil}} \def\fll{\def\lft{}} \def\flr{\def\lft{\hfill}} % \def\rowsepsurround{\vskip.1ex} % \def\vtable#1{\frameit{\hbox {\valign{\top\noindent \hsize#1\lft##\bot &&##&\hsize#1\top \noindent\lft ##\bot\cr \data}}}} \def\data{anatoly\rs andre\rs alex \cs beatrici\rs bernd\lcs} \nonframed\vtable{20ex} \enddemo} The advantage of \cs{valign} for this case is that when a name is inserted in a column that column can grow without adaptation of the markup for the other cells. \blueexample Simultaneous row and column spans These require more work. ^^{row\ and\ column\ spans} \newbox\block \setbox\block=\hbox{$2*3$} \def\data{\logms3\cs14\grs \logms3\cs24\rs 31\cs32\cs33\cs34} \def\btablecaption{Caption} \def\rowstblst{{row 1}{row 2}{\hfil $\Rightarrow$}} \def\header{\logms4 Header\hfil$\Downarrow$} \def\footer{Footer} \thisbtable{\def\ghostrow{\ifx\empty\rowstblst \else\omit\lineglue\ea\srp\fi \logms3\hfil\vbox to0pt{\vss \copy\block\vss}\hfil\prs\lineglue\cr\nxtrs} } $$\vcenter{\framed\ruled\btable\data} \qquad\qquad %\setbox\block=\hbox{$3*3$} \def\data{\logms3\hfil\cs14\grs \logms3\hfil$3*3$\hfil\cs24\grs \logms3\hfil\cs34\rs 41\cs42\cs43\cs44} \thisbtable{\def\ghostrow{\ifx\empty\rowstblst \else\omit\lineglue\ea\srp\fi \logms3\hfil\prs\lineglue\cr \ifx\empty\rowstblst\else\ea\nxtrs\fi}} \def\btablecaption{Caption} \def\header{\logms4 Header\hfil$\Downarrow$\ } \def\rowstblst{{row 1}{row 2}{row 3}{\hfil$\Rightarrow$}} \def\footer{Footer} \vcenter{\ruled\framed\btable\data} $$ \exercise How to markup the above with simultaneous row and column spans? \answer Because of the separation of concerns we only have to concentrate on the data. My approach is to look at a block\Dash here $2{*}3$\Dash as a ghost to be overprinted. A natural way is to introduce the concept of a ghostrow, which will be invoked by the ghostrow separator \cs{grs}. So first mark up for the data with the hole in the table and include the \cs{grs}. Then provide \cs{ghostrow}. In order to do the latter gracefully, we also need the concept of partial row separator, \cs{prs}, and its mirror, \cs{srp}, to handle partial lines. \beginverbatim \setbox\block=\hbox{$2*3$} \def\data{\logms3\cs14\grs \logms3\cs24\rs 31\cs32\cs33\cs34} \def\btablecaption{Caption} \def\rowstblst{{row 1}{row 2}{\hfil $\Rightarrow$}} \def\header{\logms4 Header\hfil$\Downarrow$} \def\footer{Footer} \thisbtable{\def\ghostrow{\ifx\empty\rowstblst \else\omit\lineglue\ea\srp\fi \logms3\hfil\vbox to0pt{\vss \copy\block\vss}\hfil\prs\lineglue\cr\nxtrs} }\vcenter{\framed\ruled\btable\data}$$ % %and the 3*3 block can be obtained via % %\setbox\block=\hbox{$3*3$} \def\data{\logms3\hfil\cs14\grs \logms3\hfil$3*3$\hfil\cs24\grs \logms3\hfil\cs34\rs 41\cs42\cs43\cs44} \thisbtable{\def\ghostrow{\ifx\empty\rowstblst \else\omit\lineglue\ea\srp\fi \logms3\hfil\prs\lineglue\cr \ifx\empty\rowstblst\else\ea\nxtrs\fi}} \def\btablecaption{Caption} \def\header{\logms4 Header\hfil$\Downarrow$\ } \def\rowstblst{{row 1}{row 2}{row 3}{\hfil$\Rightarrow$}} \def\footer{Footer} $$\vcenter{\ruled\framed\btable\data}$$ !endverbatim \begingroup \blueexample Gnonoms In \TUB{} a discussion about the following kind of rules within tables\Dash so-called ^{gnonoms}\Dash emerged. \newcount\rowno \rowno1 \thisverbatim{\unmc} \begindemo \newcount\columnno \columnno1 \def\data{1\cs3\cs5\rs 1\cs4\cs7\rs 1\cs5\cs9\lrs} \def\cs{\hss\vrule\ifnum \columnno<\rowno width0pt\fi\relax &\global\advance\columnno1 } \def\rs{\hss\vrule\relax\cr \global\advance\rowno1 \global\columnno1 } \def\lrs{\hss\vrule\relax\cr} \halign{&\vbox to12pt{\hbox to12pt {\hss\strut#}\vss\hrule\ifnum \rowno<\columnno width0pt\fi}\cr \data} !yields\offinterlineskip \newcount\columnno \columnno1 \def\data{1\cs3\cs5\rs 1\cs4\cs7\rs 1\cs5\cs9\lrs} \def\cs{\hss\vrule\ifnum \columnno<\rowno width0pt\fi\relax &\global\advance\columnno1 } \def\rs{\hss\vrule\relax\cr \global\advance\rowno1 \global\columnno1 } \def\lrs{\hss\vrule\relax\cr} $$\vbox{\halign{&\vbox to12pt{\hbox to12pt{\hss\strut#}\vss\hrule \ifnum\rowno<\columnno width0pt\fi\relax}\cr \data}}\qquad\qquad$$ \enddemo % %Coding with the deterministic behaviour absorbed, reads as follows. \newcount\rowno \rowno1 \newcount\columnno \columnno1 \newcount\tnum \newcount\diff \diff1 \newcount\n \def\rows{\global\tnum1 \global\advance\diff1 \cols \ifnum\rowno=\n\lrs\swor\fi \rs\rows} \def\swor#1\rows{\fi} \def\cols{\the\tnum \global\advance\tnum\diff \ifnum\columnno=\n\sloc\fi \cs\cols} \def\sloc#1\cols{\fi} \def\cs{\hss\vertrule \ifnum \columnno<\rowno width0pt\fi\relax &\global\advance\columnno1 } \def\rs{\hss\vertrule\relax\cr \global\advance\rowno1 \global\columnno1 } \def\lrs{\hss\vertrule\relax \global\columnno1 \global\rowno1 \global\diff1 \cr} % \def\gnonoms#1{\n#1 \offinterlineskip \halign{&\vbox to12pt{\hbox to15pt {\hss\strut\oldstyle##}\vss\horrule \ifnum\rowno<\columnno width0pt\fi\relax}\cr \rows}} \let\vertrule\vrule \let\horrule\hrule \exercise Each entry of the table obeys the formula $$entry_{i,j}=2j-1+(i-1)(j-1).$$ A little backside of the envelope calculation-\Dash or just look closer at the table\Dash shows that elements in neighbouring columns differ by $i+1$. Format this table as function of the size, i.e., with the elements generated automatically. \answer A solution reads as follows (Similar approach as to Pittman's multiplication tables.) \thisverbatim{\unmc} \beginverbatim \newcount\rowno \rowno1 \newcount\columnno \columnno1 \newcount\tnum \newcount\diff \diff1 \newcount\n \def\rows{\global\tnum1 \global\advance\diff1 \cols \ifnum\rowno=\n\lrs\swor\fi \rs\rows} \def\swor#1\rows{\fi} \def\cols{\the\tnum \global\advance\tnum\diff \ifnum\columnno=\n\sloc\fi \cs\cols} \def\sloc#1\cols{\fi} \def\cs{\hss\vertrule \ifnum \columnno<\rowno width0pt\fi\relax &\global\advance\columnno1 } \def\rs{\hss\vertrule\relax\cr \global\advance\rowno1 \global\columnno1 } \def\lrs{\hss\vertrule\relax \global\columnno1 \global\rowno1 \global\diff1 \cr} % \def\gnonoms#1{\n#1 \offinterlineskip \halign{&\vbox to12pt{\hbox to15pt {\hss\strut\oldstyle##}\vss\horrule \ifnum\rowno<\columnno width0pt\fi\relax}\cr \rows}} \let\vertrule\vrule \let\horrule\hrule $$\vtop{\gnonoms2}\qquad \vtop{\gnonoms5}\qquad \vtop{\gnonoms{10}}$$ \bye !endverbatim \exercise Playing longer with the gnonoms can yield the following graphical results. Modify the above in order to obtain this graph. \def\vertrule{\vrule width1ex} \def\horrule{\hrule height 1ex} \def\cols{\ifnum\columnno=\n\sloc\fi \cs\cols} $$\vtop{\gnonoms3}\qquad \vtop{\gnonoms5}\qquad \vtop{\gnonoms{7}}$$ \answer The following redefinitions yield the results. \beginverbatim \def\vertrule{\vrule width1ex} \def\horrule{\hrule height 1ex} \def\cols{\ifnum\columnno=\n\sloc\fi \cs\cols} $$\vtop{\gnonoms3}\qquad \vtop{\gnonoms5}\qquad \vtop{\gnonoms7}$$ !endverbatim \endgroup \bluesubhead Font charts Font tables can be formatted via ^|\beginchart| and |\endchart|. This markup is used in \TB{} {\oldstyle468}--{\oldstyle526}, for the font tables of the Appendices C and F, and in {\tt testfont.tex}, which comes along with \MF. \blueexample ASCII table, \TB{} {\oldstyle367} \beginverbatim \beginchart{\global\count@='41\tentt \def\chartstrut{\lower4.3pt\vbox to13.6pt{}}} &\oct{00x}&&NUL&&SOH&&STX&&ETX&&EOT&&ENQ&&ACK&&BEL&&\oddline0 &\oct{03x}&&CAN&&EM&&SUB&&ESC&&FS&&GS&&RS&&US&\evenline &\oct{04x}&&SP&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\oddline2 &\oct{05x}&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\:&\evenline \noalign{\vskip2ex\line{\hfil et cetera\hfil} \vskip2.5ex\hrule \global\advance\count@ 64 } &\oct{16x}&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\oddline7 &\oct{17x}&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&DEL&\evenline \endchart !endverbatim resulting in the partial ASCII table {\catcode`\@=11 \beginchart{\global\count@='41\postdisplaypenalty=0 \tentt \def\chartstrut{\lower4.3pt\vbox to13.6pt{}}} &\oct{00x}&&NUL&&SOH&&STX&&ETX&&EOT&&ENQ&&ACK&&BEL&&\oddline0 &\oct{03x}&&CAN&&EM&&SUB&&ESC&&FS&&GS&&RS&&US&\evenline &\oct{04x}&&SP&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\oddline2 &\oct{05x}&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\:&\evenline \noalign{\vskip2ex\line{\hfil et cetera\hfil} \vskip2.5ex\hrule\global\advance\count@ 64 } &\oct{16x}&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\oddline7 &\oct{17x}&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&DEL&\evenline \endchart } %Blank line is needed \bluesubsubhead Why bother about font charts? Well, \dots\thinspace a lot can be learned from \cs{beginchart} for the markup of classes of tables. \bitem Font charts belong to the class of bordered tables \bitem the template is hidden from the user \bitem the data can be provided separately and processed on the fly \bitem the default value of \cs{displaypenalty} can be redefined via \cs{displaypenalty} || as argument of \cs{beginchart} \bitem \cs{beginchart} is parameterized over the fonts \bitem ^|\normalchart| keeps automatically track of the positions in the font chart. \smallbreak In short, the macros show how \bitem to mark up classes of tables \bitem to hide an \cs{halign} template \bitem to use two-part macros \bitem to cope with options and defaults \bitem to parameterize over fonts, and \bitem to minimize markup. \smallbreak \blueexample Markup for Appendix F {\oldstyle427}\dash{\oldstyle432} \beginverbatim \beginchart{\postdisplaypenalty=0 \tenrm} %or \tenit, \tentt, \tenit, \tensy, \tenex \normalchart \endchart !endverbatim resulting in, for the ^{font chart} \cs{tenrm} \beginchart{\postdisplaypenalty=0 \tenrm} \normalchart \endchart \noindent The default value of \cs{postdisplaypenalty} is -{\oldstyle10000}, to enforce a page break. \exercise How can we get a print of \LaTeX's ^{line\ font}s? Why don't you print ^|\oldstyle| too, just for the fun of it? \answer Similarly, as follows. \beginverbatim \font\tenln=line10 \font\tenlnw=linew10 \beginchart{\postdisplaypenalty=0 \tenln} \normalchart \endchart \beginchart\tenlnw \normalchart \endchart !endverbatim %end of answer The argument of \cs{beginchart} is used among other things to control the kind of table: \cs{tenrm}, \cs{tenit}, \cs{tentt}, \cs{teni}, \cs{tensy}, or \cs{tenex}. The data for normal font tables is provided via |\def\normalchart{...}|. As a consequence the markup for the other tables in \TB{} Appendix F is surprisingly simple. \exercise How come that Knuth decided to implement an ordinary argument after \cs{beginchart}? If you look at \cs{begindisplay} nearly the same coding structure is used, but there the argument is optional. Subtle, very subtle these coding schemes. \answer There is no much use in providing an optional one. The font is needed and {\sl must\/} be specified. %end answer \bluesubhead Ordering table for indexing The most curious of all tables is not a table but generated each time. ^^{ordering table} \thisverbatim{\catcode`\|=12 \catcode`\!=12 \catcode`\~=0 } \begincenterverbatim \def\otindex{%Parameters: Ordering `table' \ea\chardef\csname ot \endcsname=0 %Bulk according to ASCII \def\process##1{\ea\chardef \csname ot##1\endcsname=`##1 } % \fifo abcdefghijklmnopqrstuvwxyz\ofif \chardef\otij=`y \chardef\otIJ=`y % \fifo!"##$&'()*+,-./0123456789:;<=>?@ []_`\ofif % \def\process##1{\ea\chardef \csname ot##1\endcsname=\lccode`##1 } \uppercase{\fifo abcdefghijklmnopqrstuvwxyz\ofif}} ~endcenterverbatim %Back to defaults \def\header{}\def\rowstblst{}\def\btablecaption{}\def\first{}\def\footer{} \endinput