Tbl — a Program to Format Tables†
Total Page:16
File Type:pdf, Size:1020Kb
Tbl Ð A Program to Format Tables² L. L. Cherry M. E. Lesk AT&T Bell Laboratories Murray Hill, New Jersey 07974 ABSTRACT Tbl is a document formatting preprocessor for troff or nroff which makes even fairly complex tables easy to specify and enter. Tables are made up of columns which may be independently centered, right-adjusted, left-adjusted, or aligned by decimal points. Headings may be placed over single columns or groups of columns. A table entry may contain equations, or may con- sist of several rows of text. Horizontal or vertical lines may be drawn as desired in the table, and any table or element may be enclosed in a box. For example: _________________________________________ U. S. Energy Production/Consumption _________________________________________ _________________________________________ (in quadrillion Btu) Production Consumption Year Net _________________________________________ all sources 1953 36.77 36.27 +0.51 1958 38.81 40.35 ± 1.54 1963 45.85 48.32 ± 2.47 1968 56.81 61.00 ± 4.19 1973 62.06 74.28 ± 12.22 1978 61.01 78.09 ± 17.08 1983 61.19 70.05 ± 8.86 _________________________________________1987 64.55 76.01 ± 11.46 1. Introduction. prefer to read the examples ®rst, as they show some common table arrangements. A section explaining Tbl turns a simple description of a table into a how to invoke tbl precedes the examples. To avoid troff or nroff [3] program (list of commands) that repetition, henceforth read troff as ``troff or nroff.'' prints the table. It attempts to isolate a portion of a The input to tbl is text for a document, with job that it can successfully handle and leave the tables preceded by a ``.TS'' (table start) command remainder for other programs. Thus tbl may be and followed by a ``.TE'' (table end) command. used with the equation formatting program eqn [2] Tbl processes the tables, generating troff formatting or various layout macro packages [1], [5], [6], but commands, and leaves the remainder of the text does not duplicate their functions. unchanged. The .TS and .TE lines are copied, too, so that troff page layout macros (such as the memo This memorandum is divided into two parts. formatting macros [1]) can use these lines to delimit First we give the rules for preparing tbl input; then and place tables as they see ®t. In particular, any .TS .TE some examples are shown. The description of rules arguments on the or lines are copied but is precise but technical, and the beginning user may otherwise ignored, and may be used by document layout macro commands. ²This is a version of [4] revised by Lorinda Cherry. The format of the input is as follows: Research Tenth Edition 35 Tbl Ð A Program to Format Tables tbl text linesize(n)set lines or rules (e.g. from box) .TS in n point type; table delim(xy) recognize x and y as the eqn .TE delimiters. text .TS Tbl tries to keep boxed tables on one page by table issuing appropriate troff ``need'' (.ne) commands. .TE These requests are calculated from the number of text lines in the tables, and if there are spacing com- . mands embedded in the input, these requests may be inaccurate; use normal troff procedures, such as where the format of each table is as follows: keep-release macros, in that case. The user who must have a multi-page boxed table should use mac- .TS ros designed for this purpose, as explained below options ; under `Usage.' format . data .TE 2.2. Format The format section of the table speci®es the Each table is independent, and must contain format- layout of the columns. Each line in this section ting information followed by the data to be entered corresponds to one line of the table (except that the in the table. The formatting information, which last line corresponds to all following lines up to the describes the individual columns and rows of the next .T&, if any Ð see below), and each line con- table, may be preceded by a few options that affect tains a key-letter for each column of the table. It is the entire table. A detailed description of tables is good practice to separate the key letters for each given in the next section. column by spaces or tabs. Each key-letter is one of the following: 2. Input commands. L or l to indicate a left-adjusted column entry; As indicated above, a table contains, ®rst, glo- R r bal options, then a format section describing the lay- or to indicate a right-adjusted column out of the table entries, and then the data to be entry; printed. The format and data are always required, C or c to indicate a centered column entry; but not the options. The various parts of the table N or n to indicate a numerical column entry, to are entered as follows: be aligned with other numerical entries so that the units digits of numbers line 2.1. Options up; There may be a single line of options affecting A or a to indicate an alphabetic subcolumn; all the whole table. If present, this line must follow the corresponding entries are aligned on the .TS line immediately and must contain a list of left, and positioned so that the widest is option names separated by spaces, tabs, or commas, centered within the column (see example and must be terminated by a semicolon. The allow- on page 12); able options are: S or s to indicate a spanned heading, i.e. to center center the table (default is left- indicate that the entry from the previous adjust); column continues across this column expand make the table as wide as the (not allowed for the ®rst column, obvi- current line length; ously); or box enclose the table in a box; Ã to indicate a vertically spanned heading, i.e. to indicate that the entry from the allbox enclose each item in the table in a previous row continues down through box; this row. (Not allowed for the ®rst row doublebox enclose the table in two boxes; of the table, obviously). tab (x) use x instead of tab to separate When numerical alignment is speci®ed, a loca- data items. tion for the decimal point is sought. The rightmost 36 UNIX Papers tbl Tbl Ð A Program to Format Tables dot (.) adjacent to a digit is used as a decimal Overall title point; if there is no dot adjoining a digit, the right- Item-a 34.22 9.1 most digit is used as a units digit; if no alignment is Item-b 12.65 .02 indicated, the item is centered in the column. How- Items: c,d,e 23 5.8 ever, the special non-printing character string \& Total 69.87 14.92 may be used to override unconditionally dots and There are some additional features of the key-letter digits, or to align alphabetic data; this string lines up system: where a dot normally would, and then disappears from the ®nal output. In the example below, the Horizontal lines Ð A key-letter may be replaced items shown at the left will be aligned (in a numeri- by _ (underscore) to indicate a horizontal line cal column) as shown on the right: in place of the corresponding column entry, or by = to indicate a double horizontal line. If an adjacent column contains a horizontal line, 13 13 or if there are vertical lines adjoining this 4.2 4.2 column, this horizontal line is extended to 26.4.12 26.4.12 meet the nearby lines. If any data entry is abc abc provided for this column, it is ignored and a abc\& abc warning message is printed. 43\&3.22 433.22 Vertical lines Ð A vertical bar may be placed 749.12 749.12 between column key-letters. This will cause a vertical line between the corresponding Note: If numerical data are used in the same columns of the table. A vertical bar to the left column with wider L or r type table entries, the of the ®rst key-letter or to the right of the last widest number is centered relative to the wider L or one produces a line at the edge of the table. If r items (L is used instead of l for readability; they two vertical bars appear between key-letters, a have the same meaning as key-letters). Alignment double vertical line is drawn. within the numerical items is preserved. This is Space between columns Ð A number may follow similar to the behavior of a type data, as explained the key-letter. This indicates the amount of above. However, alphabetic subcolumns (requested separation between this column and the next by the a key-letter) are always slightly indented column. The number normally speci®es the relative to L items; if necessary, the column width is separation in ens*. If the ``expand'' option is increased to force this. This is not true for n type used, then these numbers are multiplied by a entries. constant such that the table is as wide as the current line length. The default column Warning: the n and a items should not be separation number is 3. If the separation is used in the same column. changed the worst case (largest space requested) governs. For readability, the key-letters describing each column should be separated by spaces. The end of Vertical spanning Ð Normally, vertically spanned the format section is indicated by a period. The lay- items extending over several rows of the table out of the key-letters in the format section resembles are centered in their vertical range.