tbl (表格式化程序)

rose1 发表于 2020-07-13 18:27
浏览次数:
在手机上阅读

在类似Unix的操作系统上,tbl是troff,nroff和groff的表格式化程序。 本文档介绍tbl的Linux版本。

查看英文版

目录

1 tbl 运行系统环境

2 tbl 说明

3 tbl 语法

4 tbl 例子

tbl 运行系统环境

Linux

tbl 说明

GNU tbl是groff文档格式化系统的一部分。tbl将嵌入在troff输入文件中的表的描述编译成troff可以理解的命令。通常,应使用groff的-t选项调用它。它与旧版Unix tbl高度兼容。GNU tbl生成的输出无法使用Unix troff进行处理;它必须用GNU troff处理。如果在命令行上未提供任何文件,或者给出了破折号(“ - ”)的文件名,则 读取标准输入。
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.

查看英文版

查看中文版

tbl 语法

tbl [-Cv] [fles ...]

选件

-C 启用兼容模式以识别.TS和.TE,即使后面跟空格或换行符也不是。前导字符(\ a)按照解释进行处理。
-v 打印版本号,然后退出。

用法

tbl希望找到包装在.TS(表开始)和.TE(表结束)宏中的表描述。

全局选项

紧接线.TS宏可包含任何以下全局选项(忽略的情况下,字符 -的Unix TBL只接受与所有字符选项小写还是所有字符大写),由空格,制表符或逗号分隔:

allbox 将表格中的每个项目放在一个框中。
box 将表格放在一个盒子中。
center 将表格居中(默认为左对齐)。还可以识别备用关键字名称中心(这是GNU tbl扩展名)。
decmalpont(c) 设置要在数字列中识别为小数点的字符(仅GNU tbl)。
delm(xy) 使用x和y作为方程式的开始和结束定界符。
doublebox 将表格放在一个双框中。
doubleframe 与doublebox相同(仅GNU tbl)。
expand 使表格与当前行长一样宽(提供列分隔因子)。忽略是否使用一个或多个“ x”列说明符(请参见下文)。

如果列宽的总和大于当前行长,则列分隔系数设置为零;否则,列分隔系数设置为0。这样的表延伸到右边距,并且根本没有列分隔。
frame box相同(仅GNU tbl)。
lnesze(n) 在n点类型中设置行或规则(例如,从box中)。
nokeep 不要使用转移来防止分页符(仅GNU tbl)。通常,tbl尝试通过使用转移来防止装箱的表格出现意外中断,例如,在使用脚注的情况下,有时这种转移可能与宏包自己对转移的使用产生不良影响。
nospaces 忽略数据项中的前导和尾随空格(仅GNU tbl)。
nowarn 关闭与超出当前行宽的表有关的警告(仅GNU tbl)。
tab(x) 使用字符x代替制表符可分隔输入数据行中的项目。

全局选项必须以分号结尾。选项和括号中的参数之间可能会有空格。

表格格式规格

全局选项之后是描述表的每一行格式的行。每个这样的格式行都描述了表本身的一行,除了最后一个格式行(必须以句点结尾)描述了表的所有其余行。单键字符描述表的每一行的每一列。关键字符可以用空格或制表符分隔。您可以使用逗号将多行的格式规范同时放在同一行上。

您可以在每个关键字符后面加上说明符,这些说明符确定相应项目的字体和磅值,确定列宽,列间间距等。

最长的格式行定义了表格中的列数;在格式线端缺失的格式描述符被假定为大号。数据中的多余列(没有相应的格式条目)将被忽略。

可用的关键字符是:

a,A 在此列中将最长的线居中,然后将该列中的所有其他线相对于该居中线左对齐。这个想法是结合L使用这样的字母子列(因此为关键字符的名称);之所以称它们为子列,是因为A项相对于L项缩进了1 n。例:

.TStab(;);ln,an.tem one;1subtem two;2subtem three;3.T&ln,an.tem eleven;11subtem twentytwo;22subtem thrtythree;33.TE
结果:
tem one                 1 subtem two             2 subtem three           3tem eleven             11 subtem twentytwo      22 subtem thrtythree    33
c,C 列中的中心项目。
l,L 在列中左对齐项目。
n,N 用数字说明列中的项目:数字的单位位置垂直对齐。如果一个数字附近有一个或多个点,请使用最右边的一个进行垂直对齐。如果没有点,则使用最右边的数字进行垂直对齐;否则,将该项放在列的中心。可以使用' \& ' 将对齐方式强制到某个位置。如果数据中存在一个或多个此特殊字符(非打印字符),请使用最左边的一个进行对齐。例:

.TSn.11.51.5.3abcdea\&bcde.TE
结果:

1 1.51.5.3 abcde abcde
 entres (ths  delmters for that purpose.如果将数字条目与LR条目组合在一起(如果使用.T&更改表格式,则可能会发生这种情况),相对于最宽的LR条目,将最大数字(在N指定符制度下输入的数据)居中,所有数字条目的对齐方式。与A类型条目相反,没有额外的缩进。如上所述,由于tbl用于查找垂直对齐的算法,在大多数情况下,在使用N指定符的列中使用方程式(将由eqn处理)是有问题的。使用全局


delim选项,但是,可以为此目的使tbl忽略eqn分隔符内的数据。
r,R 在列中右对齐项目。
s,S 将左侧的上一个项目跨入此列。第一栏不允许。
^ 从此列的上一行向下扩展条目。第一行不允许。
_,- 将该条目替换为水平线。请注意,“ _ ”和“ - ”只能用于表字段,不能用于列分隔符行。
= 用双水平线代替该条目。请注意,“ = ”只能用于表字段,不能用于列分隔符行。
| 相应的列将成为垂直标尺(如果其中两个相邻,则为双垂直标尺)。

第一个关键字母左侧或最后一个字母右侧的竖线会在表格边缘产生一条线。

要更改表中的数据格式,请使用.T&命令(在行的开头)。其后跟类似于.TS请求的格式和数据行(但没有全局选项)。

列说明符

以下是可以在列键字母后缀中出现的说明符(以任何顺序):

b,B 简短形式的fB的(使受影响的条目粗体)。
d,D 使用“ ^ ”列说明符或“ \ ^ ”数据项在其范围的底部而不是垂直居中地启动一个垂直跨行的项目(仅适用于GNU tbl)。例:



.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 │
└─────┴────────┘
e,E 制作等距的列。用此说明符标记的所有列都具有相同的宽度;这是在计算了受影响的列宽之后发生的(这意味着最大的宽度值是规则)。
f,F 这些说明符中的任何一个都可以跟在字体名称(一个或两个字符长),字体编号(一个数字)或括号中的长名称(最后一种形式是GNU tbl扩展名)之后。一个字母的字体名称必须由一个或多个空格分隔,后跟任何空格。
, 短形式的网络连接(使受影响的条目斜体)。
m,M 此选项是GNU tbl扩展。这些说明符中的任何一个都可以跟一个宏名(一个或两个字符长)或括号中的长名。一个字母的宏名称必须由一个或多个空格分隔,后跟任何空格。在创建表之前,必须先定义可在此处指定名称的宏。在输出表格的单元格文本之前调用它。按照当前的实现,仅当使用块输入(即“ T { ”和“ T} ” 之间的文本)时才调用此宏。该宏应仅包含简单的troff请求,以更改文本块格式,例如文本调整,连字符,大小或字体。宏之后其他细胞修饰像称为b,或v输出。因此,宏可以覆盖其他修改说明符。
p,P 后面跟一个数字,这会更改受影响字段的磅值。如果已签名,则当前点的大小将增加或减少(使用GNU tbl扩展名是使用带符号的数字而不是带符号的数字)。点大小说明符后跟一个列分隔号,必须用一个或多个空格分隔。
t,T 启动一个项目,使其垂直跨越其范围顶部的行,而不是使其垂直居中。
u,U 将相应的列上移一半。
v,V 后面跟一个数字,表示在多行表条目中使用的垂直行间距。如果是带符号的,则当前垂直行间距将增加或减小(使用带符号的数字代替带符号的数字是GNU tbl扩展名)。垂直行间距说明符后跟一个列分隔号,必须用一个或多个空格分隔。如果相应的表条目不是文本块,则无效。
w,W 最小列宽值。必须后跟括号中的troff宽度表达式或无单位整数。如果未给出单位,则使用en单位。另外,用作包含的文本块的默认行长。如果多次使用以指定特定列的宽度,则最后一个条目生效。
x,X 展开的列。在不使用x指定符的情况下计算所有列宽之后,请使用此列的其余行宽。如果展开的列不止一个,请在受影响的列之间平均分配剩余的水平空间(这是GNU扩展)。此功能与指定最小列宽的效果相同。
z,Z 忽略用于宽度计算目的的相应列,即不要使用字段,而仅使用此列的指定符来计算其宽度。

键字符上的数字后缀被解释为以en为单位的列分隔符(如果打开expand选项,则按比例乘以倍数–如果表太满,则可能为零)。默认间隔为3n

列说明符xew互斥(但ew不互斥);如果多次指定为特定列,最后一个条目生效:X取消设置既ë和瓦特,而E或瓦特覆盖X

表数据

格式行之后是包含表实际数据的行,最后是.TE。在此类数据行中,项目通常由制表符(或用tab选项指定的字符)分隔。如果行中的最后一个字符为“ \ ”(在连接后消失),则长输入行可以跨多行中断。

请注意,tbl逐行计算列宽,在不是文本块的每个条目上应用\ w。结果,像

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

fal; you must ether say

.TS
cp20,lp20.
MM
MMMM
.TE

or

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

以点开头的点,其后跟数字以外的任何东西,都作为troff命令处理,不加更改地通过。在这种情况下,表的位置不变。

如果数据行仅由“ _ ”或“ = ”组成,则此时将在表上分别绘制单行或双行。如果数据行中的单个项目仅由' _或' = '组成,则该项目将替换为单行或双行,并与其相邻。如果数据项仅由' \ _ '' \ = '组成,则在该区域的不连接其邻居的点处分别绘制单行或双行。仅由' \ Rx '' x '任何字符)组成的数据项被重复字符' x ' 代替 与列一样宽(不加入其邻居)。仅由“\ ^ '表示紧邻上方的字段在此行上向下扩展。

文字块

文本块可用于将数据作为单个条目输入,这与制表符之间的简单字符串一样长。它以' T { ' 开头,以' T} '结束。前者必须以一行结尾,后者必须以一行开头,之后可能跟着其他数据列(用制表符分隔或用制表符全局选项给定的字符分隔)。

默认情况下,文本块的格式设置为进入表之前处于活动状态的设置,可能会被m,v和w tbl说明符覆盖。例如,要使所有文本块衣衫agged,请在开始的.TS前面插入.na(在表的后面插入.ad)。

如果未为文本块跨度的所有列都指定'w''x'指定符,则文本块的默认长度(更准确地说,用于处理文本块转换的行长)计算为L ×C /(N + 1),其中“ L”是当前行长,“ C”是文本块跨越的列数,而“ N”是表中的列总数。 但是请注意,寄存器\ n [dl]中返回的实际转换宽度最终将用作文本块宽度。 如有必要,您还可以在“ T {”之后直接插入.ll请求来控制文本块的宽度。

数字寄存器\ n [TW]保持表格宽度;它不能在表本身中使用,而是在调用.TE之前定义的,以便此宏可以使用它。


tbl还定义了一个宏.T#,该宏产生装箱表的底线和边线。尽管tbl确实在表的末尾调用了此宏本身,但是宏包可以使用它通过在页脚中调用它来为多页表创建框。如果表以.TS H开头而不是对.TS宏的标准调用,则-ms宏将显示此功能的示例。


与eqn的交互

tbl应该始终在eqn之前而不是之后调用。(groff自动处理正确的预处理程序顺序。)

GNU tbl增强功能

对表中的列数没有限制,对文本块的数量也没有任何限制。在确定列宽时,不仅要考虑前200行,还要考虑表中的所有行。表延续(.T&)行不限于前200行。

数字和字母项目可能会出现在同一列中。

数字和字母项目可能会水平分布。

tbl使用以数字3开头的寄存器,字符串,宏和转移名称。使用tbl时,应避免使用以3开头的任何名称。


宏内的GNU tbl

由于tbl定义了自己的宏(在每个表之前),因此有必要使用“宏结束”宏。此外,必须关闭转义字符。这是一个例子:

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

但是请注意,并非tbl的所有功能都可以包装到宏中,因为tbl早于troff看到输入。例如,如果将这些数字作为宏参数传递,则使用垂直对齐的小数点进行数字格式化将失败,因为小数点对齐由tbl本身处理:它只能看到' \ $ 1 ',' \ $ 2 '等,因此可以' t识别小数点。


漏洞

对于所有多页装箱表,应将.TS H / .TH与支持的宏程序包结合使用。如果您不想在表的每一页顶部显示标题,请在格式部分之后立即放置.TH行。不要在保留/释放宏中包含多页表,也不要以任何其他方式转移它。


表格中的文本块必须能够容纳在一页上。

BP请求不能被用于强制在多页表中的分页符。相反,请按以下方式定义BP

.de BP
.  e '\\n(.z'' .bp \\$1
.  el \!.BP \\$1
..

并使用BP代替bp

直接在表中使用\ a来获取领导者是行不通的(在兼容模式下除外)。这是正确的行为:\ a是无法解释的领导者。要获得领导者,可以使用控件A或类似的方式使用真正的领导者:

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

开头和/或结尾的' | '的格式行,例如


|l r|.

给出的输出在结果边界垂直法线和相邻列的内容之间具有1n的间距,如


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

如果希望空间为零(以便规则触及内容),则可以通过在之前和/或之后引入没有内容且零分隔的额外“虚拟”列来实现,如

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

生成的“虚拟”列不可见,并且宽度为零;请注意,此类列通常不适用于TTY设备。

tbl [-Cv] [files ...]

Options

-C Enable compatibility mode to recognize .TS and .TE even when followed by a character other than space or newline. Leader characters (\a) are handled as interpreted.
-v Print the version number, and exit.

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:

allbox Enclose each item of the table in a box.
box Enclose the table in a box.
center Center the table (default is left-justified). The alternative keyword name centre is also recognized (this is a GNU tbl extension).
decimalpoint(c) Set the character to be recognized as the decimal point in numeric columns (GNU tbl only).
delim(xy) Use x and y as start and end delimiters for eqn.
doublebox Enclose the table in a double box.
doubleframe Same as doublebox (GNU tbl only).
expand Make the table as wide as the current line length (providing a column separation factor). Ignored if one or more "x" column specifiers are used (see below).

In case the sum of the column widths is larger than the current line length, the column separation factor is set to zero; such tables extend into the right margin, and there is no column separation at all.
frame Same as box (GNU tbl only).
linesize(n) Set lines or rules (e.g., from box) in n-point type.
nokeep Don't use diversions to prevent page breaks (GNU tbl only). Normally tbl attempts to prevent undesirable breaks in boxed tables by using diversions, which can sometimes interact badly with macro packages' own use of diversions, when footnotes, for example, are used.
nospaces Ignore leading and trailing spaces in data items (GNU tbl only).
nowarn Turn off warnings related to tables exceeding the current line width (GNU tbl only).
tab(x) Use the character x instead of a tab to separate items in a line of input data.

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,A Center longest line in this column and then left-justifies all other lines in this column with respect to that centered line. The idea is to use such alphabetic subcolumns (hence the name of the key character) in combination with L; they are called subcolumns because A items are indented by 1n relative to L entries. Example:

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

item one                 1 subitem two             2 subitem three           3item eleven             11 subitem twentytwo      22 subitem thirtythree    33
c,C Center item within the column.
l,L Left-justify item within the column.
n,N Numerically justify item in the column: Units positions of numbers are aligned vertically. If there is one or more dots adjacent to a digit, use the rightmost one for vertical alignment. If there is no dot, use the rightmost digit for vertical alignment; otherwise, center the item within the column. Alignment can be forced to a certain position using '\&'; if there is one or more instances of this special (non-printing) character present within the data, use the leftmost one for alignment. Example:

.TSn.11.51.5.3abcdea\&bcde.TE
Result:

1 1.51.5.3 abcde abcde
If numerical entries are combined with L or R entries (this can happen if the table format is changed with .T&), center the widest number (of the data entered under the N specifier regime) relative to the widest L or R entry, preserving the alignment of all numerical entries. Contrary to A type entries, there is no extra indentation.

Using equations (to be processed with eqn) within columns which use the N specifier is problematic in most cases due to tbl's algorithm for finding the vertical alignment, as described above. Using the global delim option, however, it is possible to make tbl ignore the data within eqn delimiters for that purpose.
r,R Right-justify item within the column.
s,S Span previous item on the left into this column. Not allowed for the first column.
^ Span down entry from previous row in this column. Not allowed for the first row.
_,- Replace this entry with a horizontal line. Note that "_" and "-" can be used for table fields only, not for column separator lines.
= Replace this entry with a double horizontal line. Note that "=" can be used for table fields only, not for column separator lines.
| The corresponding column becomes a vertical rule (if two of these are adjacent, a double vertical rule).

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.

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):

b,B Short form of fB (make affected entries bold).
d,D Start an item that vertically spans rows, using the "^" column specifier or "\^" data item, at the bottom of its range rather than vertically centering it (GNU tbl only). Example:

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

┌─────┬────────┐
│0000 │ foobar │
├─────┼────────┤
│1111 │        │
│2222 │        │
├─────┤        │
│   r │ foo    │
├─────┼────────┤
│3333 │        │
│4444 │    bar │
└─────┴────────┘
e,E Make equally-spaced columns. All columns marked with this specifier get the same width; this happens after the affected column widths have been computed (this means that the largest width value rules).
f,F Either of these specifiers may be followed by a font name (either one or two characters long), font number (a single digit), or long name in parentheses (the last form is a GNU tbl extension). A one-letter font name must be separated by one or more blanks from whatever follows.
i,I Short form of fI (make affected entries italic).
m,M This option is a GNU tbl extension. Either of these specifiers may be followed by a macro name (either one or two characters long), or long name in parentheses. A one-letter macro name must be separated by one or more blanks from whatever follows. The macro which name can be specified here must be defined before creating the table. It is called just before the table's cell text is output. As implemented currently, this macro is only called if block input is used, that is, text between "T{" and "T}". The macro should contain only simple troff requests to change the text block formatting, like text adjustment, hyphenation, size, or font. The macro is called after other cell modifications like bf or v are output. Thus the macro can overwrite other modification specifiers.
p,P Followed by a number, this does a point size change for the affected fields. If signed, the current point size is incremented or decremented (using a signed number instead of a signed digit is a GNU tbl extension). A point size specifier followed by a column separation number must be separated by one or more blanks.
t,T Start an item vertically spanning rows at the top of its range rather than vertically centering it.
u,U Move the corresponding column up one half-line.
v,V Followed by a number, this indicates the vertical line spacing to be used in a multi-line table entry. If signed, the current vertical line spacing is incremented or decremented (using a signed number instead of a signed digit is a GNU tbl extension). A vertical line spacing specifier followed by a column separation number must be separated by one or more blanks. No effect if the corresponding table entry isn't a text block.
w,W Minimum column width value. Must be followed either by a troff width expression in parentheses or a unitless integer. If no unit is given, en units are used. Also, used as the default line length for included text blocks. If used multiple times to specify the width for a particular column, the last entry takes effect.
x,X An expanded column. After computing all column widths without an x specifier, use the remaining line width for this column. If there is more than one expanded column, distribute the remaining horizontal space evenly among the affected columns (this is a GNU extension). This feature has the same effect as specifying a minimum column width.
z,Z Ignore the corresponding column for width-calculation purposes, this is, don't use the fields but only the specifiers of this column to compute its width.

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.

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 mv, 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, either by 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.

查看英文版

查看中文版

tbl 例子

给定文件table.txt,其中包含以下tbl命令:

.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

...然后将以下tbl命令通过管道传递给nroff命令:

tbl table.txt | nroff -T ascii

...将以ASCII格式生成下表:

+-----+--------+
|0000 | foobar |
+-----+--------+
|1111 |        |
|2222 |        |
+-----+        |
|   r | foo    |
+-----+--------+
|3333 |        |
|4444 |    bar |
+-----+--------+

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 |
+-----+--------+

查看英文版

查看中文版

其他命令行

tabs | tac | talk | tail | tcopy | tty | tar | tcpdump | tcsh | time | tee | timex | telinit | telnet | test | top | touch | tput | tr | troff | traceroute |

如此好文,分享给朋友
发表评论
验证码:
评论列表
共0条