5.12 Tabs and Fields

A tab character (ISO code point 9, EBCDIC code point 5) causes a horizontal movement to the next tab stop, if any.

Escape sequence: \t

Interpolate a tab in copy mode; see Copy Mode.

Request: .ta [[n1 n2nn ]T r1 r2rn]
Register: \n[.tabs]

Change tab stop positions. This request takes a series of tab specifiers as arguments (optionally divided into two groups with the letter ‘T’) that indicate where each tab stop is to be, overriding any previous settings. The default scaling unit is ‘m’. Invoking ta without an argument removes all tab stops. GNU troff’s startup value is ‘T 0.5i.

Tab stops can be specified absolutely—as distances from the left margin. The following example sets six tab stops, one every inch.

.ta 1i 2i 3i 4i 5i 6i

Tab stops can also be specified using a leading ‘+’, which means that the specified tab stop is set relative to the previous tab stop. For example, the following is equivalent to the previous example.

.ta 1i +1i +1i +1i +1i +1i

GNU troff supports an extended syntax to specify repeating tab stops. These stops appear after a ‘T’ argument. Their values are always taken as distances relative to the previous tab stop. This is the idiomatic way to specify tab stops at equal intervals in groff. The following is, yet again, the same as the previous examples. It does more, in fact, since it defines an infinite number of tab stops at one-inch intervals.

.ta T 1i

Now we are ready to interpret the full syntax given above. The ta request sets tabs at positions n1, n2, …, nn, then at nn+r1, nn+r2, …, nn+rn, then at nn+rn+r1, nn+rn+r2, …, nn+rn+rn, and so on.

For example, ‘4c +6c T 3c 5c 2c’ is equivalent to ‘4c 10c 13c 18c 20c 23c 28c 30c …’.

Text written to a tab column (i.e., between two tab stops, or between a tab stop and an output line boundary) may be aligned to the right or left, or centered in the column. This alignment is determined by appending ‘R’, ‘L’, or ‘C’ to the tab specifier. The default is ‘L’.

.ta 1i 2iC 3iR

The beginning of an output line is not a tab stop; the text that begins an output line is placed according to the configured alignment and indentation; see Manipulating Filling and Adjustment and Line Layout.

A tab stop is converted into a non-breakable horizontal movement that cannot be adjusted.

.ll 2i
.ds foo a\tb\tc
.ta T 1i
\*[foo]
    error→ warning: cannot break line
    ⇒ a         b         c

The above creates a single output line that is a bit longer than two inches (we use a string to show exactly where the tab stops are). Now consider the following.

.ll 2i
.ds bar a\tb c\td
.ta T 1i
\*[bar]
    error→ warning: cannot adjust line
    ⇒ a         b
    ⇒ c       d

GNU troff first converts the line’s tab stops into unbreakable horizontal movements, then breaks after ‘b’. This usually isn’t what you want.

Superfluous tab characters—those that do not correspond to a tab stop—are ignored except for the first, which delimits the characters belonging to the last tab stop for right-alignment or centering.

.ds Z   foo\tbar\tbaz
.ds ZZ  foo\tbar\tbazqux
.ds ZZZ foo\tbar\tbaz\tqux
.ta 2i 4iR
\*[Z]
.br
\*[ZZ]
.br
\*[ZZZ]
.br
    ⇒ foo                 bar              baz
    ⇒ foo                 bar           bazqux
    ⇒ foo                 bar              bazqux

The first line right-aligns “baz” within the second tab stop. The second line right-aligns “bazqux” within it. The third line right-aligns only “baz” because of the additional tab character, which marks the end of the text occupying the last tab stop defined.

Tab stops are associated with the environment (see Environments).

The read-only register .tabs contains a string representation of the current tab settings suitable for use as an argument to the ta request.66

.ds tab-string \n[.tabs]
\*[tab-string]
    ⇒ T120u
Request: .tc [c]

Set the tab repetition character to the ordinary or special character c; normally, no glyph is written when moving to a tab stop (and some output devices may output space characters to achieve this motion). A tab repetition character causes the formatter to write as many instances of c as are necessary to occupy the interval from the horizontal drawing position to the next tab stop. With no argument, GNU troff reverts to the default behavior. The tab repetition character is associated with the environment (see Environments). Only a single character of c is recognized; any excess is ignored.

Request: .linetabs n
Register: \n[.linetabs]

If n is missing or non-zero, activate line-tabs; deactivate it otherwise (the default). Active line-tabs cause GNU troff to compute tab distances relative to the start of the output line instead of the input line.

.de Tabs
.  ds x a\t\c
.  ds y b\t\c
.  ds z c
.  ta 1i 3i
\\*x
\\*y
\\*z
..
.Tabs
.br
.linetabs
.Tabs
    ⇒ a         b         c
    ⇒ a         b                   c

Line-tabs activation is associated with the environment (see Environments). The read-only register .linetabs interpolates 1 if line-tabs are active, and 0 otherwise.