5.12 Tabs and Fields

A tab character (code point 9) 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]

Set 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 arguments 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 between two tab stops may be aligned to the right or left, or centered. 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
.ta T 1i
a→b→c
    error→ warning: cannot break line
    ⇒ a         b         c

The above creates a single output line that is a bit longer than two inches. Now consider the following.

.ll 2i
.ta T 1i
a→b c→d
    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.

.nf
.ta 2i 4iR
\l'4i\&-'
foo→bar
foo→bar→baz
foo→bar→bazqux
foo→bar→baz→qux
    ⇒ ----------------------------------------
    ⇒ foo                 bar
    ⇒ foo                 bar              baz
    ⇒ foo                 bar           bazqux
    ⇒ foo                 bar              bazqux

We see that “bar” is between the first and second tab stops, not the second and (nonexistent) third. The first “baz” is right-aligned within the second tab stop. The second is catenated with “qux” and right-aligned within it. The third “baz” is aligned like the first because the tab character after it determines the right boundary of the tab stop.

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.80

.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 [b]
Register: \n[.linetabs]

Activate or deactivate line-tabs in the environment per Boolean expression b. They are inactive by default, and activated if b is omitted. When line-tabs are active, tab stops are computed relative to the start of the pending output line instead of the drawing position corresponding to the start of the input line.

.ta 1i 3i
a→\c
b→\c
c
.br
.linetabs
a→\c
b→\c
c
    ⇒ a         b         c
    ⇒ a         b                   c

The read-only register .linetabs interpolates 1 if line-tabs are active, and 0 otherwise.