On Unix-like operating systems, tbl is a table formatter for troff, nroff, and groff.

This page covers the Linux version of tbl.

Description

GNU tbl is part of the groff document formatting system. tbl compiles descriptions of tables embedded within troff input files into commands that are understood by troff. Normally, it should be invoked using the -t option of groff. It is highly compatible with legacy Unix tbl. The output generated by GNU tbl cannot be processed with Unix troff; it must be processed with GNU troff. If no files are given on the command line or a file name of a dash ("-") is given, the standard input is read.

  • Description
  • Syntax
  • Global options
  • Table format specification
  • Column specifiers
  • Table data
  • Text blocks
  • Miscellaneous
  • Interaction with eqn
  • Global tbl enhancements
  • GNU tbl within macros
  • Bugs
  • Examples
  • Related commands
  • Linux commands help

Syntax

tbl [-Cv] [files …]

Options

Usage

tbl expects to find table descriptions wrapped in the .TS (table start) and .TE (table end) macros.

Global options

The line immediately following the .TS macro may contain any of the following global options (ignoring the case of characters – Unix tbl only accepts options with all characters lowercase or all characters uppercase), separated by spaces, tabs, or commas:

The global options must end with a semicolon. There might be whitespace between an option and its argument in parentheses.

Table format specification

After global options come lines describing the format of each line of the table. Each such format line describes one line of the table itself, except that the last format line (which you must end with a period) describes all remaining lines of the table. A single-key character describes each column of each line of the table. Key characters can be separated by spaces or tabs. You may run format specifications for multiple lines together on the same line by separating them with commas.

You may follow each key character with specifiers that determine the font and point size of the corresponding item, that determine column width, inter-column spacing, etc.

The longest format line defines the number of columns in the table; missing format descriptors at the end of format lines are assumed to be L. Extra columns in the data (which have no corresponding format entry) are ignored.

The available key characters are:

A vertical bar to the left of the first key letter or to the right of the last one produces a line at the edge of the table.

.TStab(;);ln,an.item one;1subitem two;2subitem three;3.T&ln,an.item eleven;11subitem twentytwo;22subitem thirtythree;33.TE

item one 1 subitem two 2 subitem three 3item eleven 11 subitem twentytwo 22 subitem thirtythree 33

.TSn.11.51.5.3abcdea&bcde.TE

1 1.51.5.3 abcde abcde

To change the data format within a table, use the .T& command (at the start of a line). It is followed by format and data lines (but no global options) similar to the .TS request.

Column specifiers

Here are the specifiers that can appear in suffixes to column key letters (in any order):

A number suffix on a key character is interpreted as a column separation in en units (multiplied in proportion if the expand option is on – in case of overfull tables this might be zero). Default separation is 3n.

.TStab(;) allbox;l ll ldr ^l rd.0000;foobarT{1111.br2222T};foor;T{3333.br4444T};bar^;^.TE

┌─────┬────────┐│0000 │ foobar │├─────┼────────┤│1111 │ ││2222 │ │├─────┤ ││ r │ foo │├─────┼────────┤│3333 │ ││4444 │ bar │└─────┴────────┘

The column specifier x is mutually exclusive with e and w (but e is not mutually exclusive with w); if specified multiple times for a particular column, the last entry takes effect: x unsets both e and w, while either e or w overrides x.

Table data

The format lines are followed by lines containing the actual data for the table, followed finally by .TE. Within such data lines, items are normally separated by tab characters (or the character specified with the tab option). Long input lines can be broken across multiple lines if the last character on the line is “" (which vanishes after concatenation).

Note that tbl computes the column widths line by line, applying \w on each entry which isn’t a text block. As a consequence, constructions like

.TS c,l. \s[20]MM MMMM .TE

fail; you must either say

.TS cp20,lp20. MM MMMM .TE

or

.TS c,l. \s[20]MM \s[20]MMMM .TE

A dot starting a line, followed by anything but a digit is handled as a troff command, passed through without changes. The table position is unchanged in this case.

If a data line consists of only “” or ‘=’, a single or double line, respectively, is drawn across the table at that point; if a single item in a data line consists of only ‘’ or ‘=’, then that item is replaced by a single or double line, joining its neighbours. If a data item consists only of ‘_’ or ‘=’, a single or double line, respectively, is drawn across the field at that point which does not join its neighbours. A data item consisting only of ‘\Rx’ (‘x’ any character) is replaced by repetitions of character ‘x’ as wide as the column (not joining its neighbours). A data item consisting only of ‘^’ indicates that the field immediately above spans downward over this row.

Text blocks

A text block can be used to enter data as a single entry which would be too long as a simple string between tabs. It is started with ‘T{’ and closed with ‘T}’. The former must end a line, and the latter must start a line, probably followed by other data columns (separated with tabs or the character given with the tab global option).

By default, the text block is formatted with the settings which were active before entering the table, possibly overridden by the m, v, and w tbl specifiers. For example, to make all text blocks ragged-right, insert .na right before the starting .TS (and .ad after the table).

If either ‘w’ or ‘x’ specifiers are not given for all columns of a text block span, the default length of the text block (to be more precise, the line length used to process the text block diversion) is computed as L×C/(N+1), where ‘L’ is the current line length, ‘C’ the number of columns spanned by the text block, and ‘N’ the total number of columns in the table. Note, however, that the actual diversion width as returned in register \n[dl] is used eventually as the text block width. If necessary, you can also control the text block width with a direct insertion of a .ll request right after ‘T{’.

Miscellaneous

The number register \n[TW] holds the table width; it can’t be used within the table itself but is defined right before calling .TE so that this macro can make use of it.

tbl also defines a macro .T# which produces the bottom and side lines of a boxed table. While tbl does call this macro itself at the end of the table, it can be used by macro packages to create boxes for multi-page tables by calling it within the page footer. An example of this is shown by the -ms macros which provide this functionality if a table starts with .TS H instead of the standard call to the .TS macro.

Interaction with eqn

tbl should always be called before eqn, not after. (groff automatically takes care of the correct order of preprocessors.)

GNU tbl enhancements

There is no limit on the number of columns in a table, nor any limit on the number of text blocks. All the lines of a table are considered in deciding column widths, not just the first 200. Table continuation (.T&) lines are not restricted to the first 200 lines.

Numeric and alphabetic items may appear in the same column.

Numeric and alphabetic items may span horizontally.

tbl uses register, string, macro and diversion names beginning with the digit 3. When using tbl you should avoid using any names beginning with a 3.

GNU tbl within macros

Since tbl defines its own macros (right before each table) it is necessary to use an ’end-of-macro’ macro. Additionally, the escape character has to be switched off. Here is an example:

.eo .de ATABLE .. .TS allbox tab(;); cl. $1;$2 .TE … .ec .ATABLE A table .ATABLE Another table .ATABLE And “another one”

Note, however, that not all features of tbl can be wrapped into a macro because tbl sees the input earlier than troff. For example, number formatting with vertically aligned decimal points fails if those numbers are passed on as macro parameters because decimal point alignment is handled by tbl itself: It only sees ‘$1’, ‘$2’, etc., and therefore can’t recognize the decimal point.

Bugs

You should use .TS H/.TH in conjunction with a supporting macro package for all multi-page boxed tables. If there is no header that you want to appear at the top of each page of the table, place the .TH line immediately after the format section. Do not enclose a multi-page table within keep/release macros, or divert it in any other way.

A text block within a table must be able to fit on one page.

The bp request cannot be used to force a page-break in a multi-page table. Instead, define BP as follows:

.de BP . ie ‘\n(.z’’ .bp \$1 . el !.BP \$1 ..

and use BP instead of bp.

Using \a directly in a table to get leaders does not work (except in compatibility mode). This is correct behaviour: \a is an uninterpreted leader. To get leaders, use a real leader, using a control A or like this:

.ds a \a .TS tab(;); lw(1i) l. A*a;B .TE

A leading and/or trailing ‘|’ in a format line, such as

|l r|.

gives output which has a 1n space between the resulting bordering vertical rule and the content of the adjacent column, as in

.TS tab(#); |l r|. left column#right column .TE

If it is desired to have zero space (so that the rule touches the content), this can be achieved by introducing extra “dummy” columns, with no content and zero separation, before and/or after, as in

.TS tab(#); r0|l r0|l. #left column#right column# .TE

The resulting “dummy” columns are invisible and have zero width; note that such columns usually don’t work with TTY devices.

Examples

Given a file, table.txt, containing the following tbl commands:

.TS tab(;) allbox; l l l ld r ^ l rd. 0000;foobar T{ 1111 .br 2222 T};foo r; T{ 3333 .br 4444 T};bar ^;^ .TE

…then the following tbl command, piped to the nroff command:

tbl table.txt | nroff -T ascii

…will produce the following table, in ASCII format:

+—–+——–+ |0000 | foobar | +—–+——–+ |1111 | | |2222 | | +—–+ | | r | foo | +—–+——–+ |3333 | | |4444 | bar | +—–+——–+

eqn — Language processor for describing equations.nroff — Format documents for terminal display or line-printer.troff — Typeset or format documents for terminal display or line-printer.