Gray background on alternate rows

Last-Updated: 2021-12-12

Sources

Introduction

Large or unusual tables can be hard to read. Adding a gray background on alternate rows can help mitigate this issue. Implementations of this feature can be found in HDTBL or can be crafted with a custom macro.

Using HDTBL

The HDTBL macro package provides many options and two of them are of interest here, fgc and bgc. As specified by the groff_hdtbl(7) man page these options control the background and foreground colour of the table cells.

bgc=[c]

The background colour of the table cells. This includes the area specified with the ‘csp’ argument. The argument ‘bgc=’ (no value) suppresses a background colour; this makes the background transparent.

Default: ‘bgc=bisque’ (string ‘t*bgc’).

fgc=c

The foreground colour of the cell contents.

Default: ‘fgc=red4’ (string ‘t*fgc’).

A custom macro by Tadziu Hoffmann

One can also use the tbl(1) preprocessor with a custom macro. Tadziu Hoffmann did just that and shared it (2021-11/msg00110).

Blake McBride used this macro and encountered some issues when a table spans pages so he edited the macro and also shared it (2021-11/msg00103).