groff_hdtbl(7) | Miscellaneous Information Manual | groff_hdtbl(7) |
groff_hdtbl - Heidelberger table macros for GNU roff
The hdtbl macros consist of four base and three optional macros, controlled by about twenty arguments. The syntax is simple and similar to the HTML table model and nearly as flexible: you can write sequences of tokens (macro calls with their arguments and content data), separated by blanks and beginning with a macro call, into the same line to get compact and cleanly arrranged input. An advantage of hdtbl is that the tables are constructed without calling a preprocessor; this means that groff(7)'s full macro capabilities are available. On the other hand, table processing with hdtbl is much slower than using the tbl(1) preprocessor. A further advantage is that the HTML-like syntax of hdtbl will be easily converted to HTML; this is not implemented yet.
In this and the next section, we present examples to help users understand the basic workflow of hdtbl. First of all, you must load the hdtbl.tmac file. As with nearly all other groff macro packages, there are two possibilities to do so: Either add the line
.mso hdtbl.tmac
to your roff file before using any macros of the hdtbl package, or add the option
-m hdtbl
to the command line of groff (before the document file which contains hdtbl macros). Then you can include on or more tables in your document, where each one must be started and ended with the .TBL and .ETB macros, respectively.
In this man page, we approximate the result of each example as terminal output to be as generic as possible since hdtbl currently only supports the ps and pdf output drivers.
The simplest well-formed table consists of just single calls to the four base table macros in the right order. Here we construct a table with only one cell.
.TBL .TR .TD contents of the table cell .ETB
A terminal representation is
+------------------------------------------------------+ | contents-of-the-table-cell | +------------------------------------------------------+
Equivalent to the above is the following notation.
.TBL .TR .TD "contents of the table cell" .ETB
By default, the formatted table is inserted into the surrounding text at the place of its definition. If the vertical space isn't sufficient, it is placed at the top of the next page. Tables can also be stored for later insertion.
Using ‘row-number*column-number’ as the data for the table cells, a table with two rows and two columns can be written as
.TBL cols=2 . TR .TD 1*1 .TD 1*2 . TR .TD 2*1 .TD 2*2 .ETB
A terminal representation is
+--------------------------+---------------------------+ | 1*1 | 1*2 | +--------------------------+---------------------------+ | 2*1 | 2*2 | +--------------------------+---------------------------+
Here we see a difference from HTML tables: The number of columns must be explicitly specified using the ‘cols=m’ argument (or indirectly via the ‘width’ argument, see below).
The contents of a table cell is arbitrary; for example, it can be another table, without restriction to the nesting depth. A given table layout can be either constructed with suitably nested tables or with proper arguments to .TD and .TH, controlling column and row spanning. Note, however, that this table
.TBL . TR . TD . nop 1*1 1*2 . TR . TD . TBL cols=2 border= . TR . TD . nop 2*1 . TD . nop 2*2 . ETB .ETB
and this table
.TBL cols=2 . TR . TD colspan=2 . nop 1*1 1*2 . TR . TD . nop 2*1 . TD . nop 2*2 .ETB
are similar but not identical (the use of .nop is purely cosmetic to get proper indentation).
The first table looks like
+------------------------------------------------------+ | 1*1 1*2 | +------------------------------------------------------+ | | | 2*1 2*2 | | | +------------------------------------------------------+
and the second one like
+------------------------------------------------------+ | 1*1 1*2 | +---------------------------+--------------------------+ | 2*1 | 2*2 | +---------------------------+--------------------------+
Here is the latter table in a more compact form.
.TBL cols=2 .TR ".TD colspan=2" 1*1 1*2 . TR .TD 2*1 .TD 2*2 .ETB
If a macro has one or more arguments (see below), and it is not starting a line, everything belonging to this macro including the macro itself must be enclosed in double quotes.
The order of macro calls and other tokens follows the HTML model. In the following list, valid predecessors and successors of all hdtbl macros are given, together with the possible arguments.
Macro arguments are separated by blanks. The order of arguments is arbitrary; they are of the form
or
with the only exception of the optional argument of the macro .ETB, which is the string ‘hold’. Another possible form is
However, this is limited to the case where the macro is the first one in the line and not already enclosed in double quotes.
Argument values specified below as c are colors predefined by groff or colors defined by the user with the .defcolor request. Argument values d are decimal numbers with or without decimal point. Argument values m are natural numbers. Argument values n are numerical values with the usual groff scaling indicators. Some of the arguments are specific to one or two macros, but most of them can be specified with .TBL, .TR, .TD, and .TH. These common arguments are explained in the next subsection.
Most of the argument default values can be changed by the user by setting corresponding default registers or strings, as listed below.
.TR .TD 1*1 ".TD 1*2 rowspan=2" .TD 1*3 .TR ".TD 2*1 colspan=2" .TD 2*3
A working example for headers and cells with colspan is
.TBL cols=3 . TR ".TH colspan=2" header1+2 .TH header3 . TR .TD 1*1 .TD 1*2 .TD 1*3 . TR .TD 2*1 ".TD colspan=2" 2*2+3 .ETB
This looks like
+------------------------------+---------------+ | header1+2 | header3 | +--------------+---------------+---------------+ | 1*1 | 1*2 | 1*3 | +--------------+---------------+---------------+ | 2*1 | 2*2+3 | +--------------+-------------------------------+
A working example with rowspan is
.TBL cols=3 . TR . TD 1*1 . TD rowspan=2 1+2*2 . TD 1*3 . . TR . TD 2*1 . TD 2*3 .ETB
which looks like
+--------------+---------------+---------------+ | 1*1 | 1+2*2 | 1*3 | +--------------+ +---------------+ | 2*1 | | 2*3 | +--------------+---------------+---------------+
The arguments described in this section can be specified with the .TBL and .TR macros, but they are eventually passed on to the table cells. If omitted, the defaults take place, which the user can change by setting the corresponding default registers or strings, as documented below. Setting an argument with the .TBL macro has the same effect as setting it for all rows in the table. Setting an argument with a .TR macro has the same effect as setting it for all the .TH or .TD macro in this row.
Before creating the first table, you should configure default values to minimize the markup needed in each table. The following example sets up defaults suitable for typical papers:
.ds t*bgc white\" background color .ds t*fgc black\" foreground color .ds t*bc black\" border color .nr t*cpd 0.1n\" cell padding
The file /usr/share/doc/groff-base/examples/hdtbl/common.roff provides another example setup in the “minimal Page setup” section.
A table which does not fit on a partially filled page is printed automatically on the top of the next page if you append the little utility macro t*hm to the page header macro of your document's main macro package. For example, say
.am pg@top . t*hm ..
if you use the ms macro package.
The macro t*EM checks for held or kept tables, and for missing ETB macros (table not closed). You can call this macro by appending it the to end-of-input macro of the main, or “full-service”, macro package your document uses. For example, try
.am pg@end-text . t*EM ..
Please send your comments to the groff mailing list or directly to the author.
The hdtbl macro package was written by Joachim Walsdorff.
31 March 2024 | groff 1.23.0 |