Welcome to the UK List of
TeX Frequently Asked Questions
on the Web

Searching

The index of Frequently Asked Questions about TeX is searchable.

Please enter your keyword here:   then press here: ,    or:
Google

Spacing lines in tables

(La)TeX mechanisms for maintaining the space between lines (the “leading”) rely on TeX’s paragraph builder, which compares the shape of consecutive lines and adjusts the space between them.

These mechanisms can’t work in exactly the same way when (La)TeX is building a table, because the paragraph builder doesn’t get to see the lines themselves. As a result, tables sometimes typeset with lines uncomfortably close together (or occasionally ridiculously far apart).

Traditional (moving metal type) typographers would adjust the spacing between lines of a table by use of a “strut” (a metal spacer). A TeX user can do exactly the same thing: most macro packages define a \strut command, that defines a space appropriate to the current size of the text; placing a \strut command at the end of a troublesome row is the simplest solution to the problem — if it works. Other solutions below are LaTeX-specific, but some may be simply translated to Plain TeX commands.

If your table exhibits a systematic problem (i.e., every row is wrong by the same amount) use \extrarowheight, which is defined by the array package:

\usepackage{array}% in the preamble
...
\setlength{\extrarowheight}{length}
\begin{tabular}{....}

To correct a single row whose maladjustment isn’t corrected by a \strut command, you can define your own, using \rule{0pt}{length} — which is a near approximation to the command that goes inside a \strut. The bigstrut package defines a strut command that you can use for this purpose: \bigstrut on its own opens up both above and below the current line; \bigstrut[t] opens up above the line, \bigstrut[b] opens up below the line.

General solutions are available, however. The tabls package automatically generates an appropriately-sized strut at the end of each row. Its disadvantages are that it’s really rather slow in operation (since it gets in the way of everything within tables) and its (lack of) compatibility with other packages.

The makecell package provides a command \gape that may be used to apply strut expansion for a single cell of a table:

\begin{tabular}{lll}
  ... & \gape{cell contents} & ... \\
  ...
\end{tabular}

The package’s similar \Gape command provides the same function, but with optional arguments that allow you to adjust the top and bottom adjustment.

To adjust every cell in whole tables, the \setcellgapes{<value>} sets the adjustment value (an optional argument of “t” or “b” restricts adjustment to the top or bottom of each cell, respectively). Having issued \setcellgapes, the command \makegapedcells switches cell expansion on, and \nomakegapedcells switches it off again.

The cellspace package does a (possibly inferior) job by defining a new table/array column type “S”, which you apply to each column specification. So, for example,

\begin{tabular}{l l l p{3cm}}

would become

\begin{tabular}{Sl Sl Sl Sp{3cm}}

and so on. This technique shows promise of not interfering so much with other packages, but this author has heard of no reports from the field.

The booktabs package comes with a thought-provoking essay about how tables should be designed. Since table row-spacing problems most often appear in collisions with rules, the author’s thesis, that LaTeX users tend too often to rule their tables, is interesting. The package provides rule commands to support the author’s scheme, but deals with inter-row spacing too. The most recent release of booktabs sports compatibility with packages such as longtable.

array.sty
Distributed as part of macros/latex/required/tools (or browse the directory); catalogue entry
bigstrut.sty
macros/latex/contrib/multirow (or browse the directory); catalogue entry
booktabs.sty
macros/latex/contrib/booktabs (or browse the directory); catalogue entry
cellspace.sty
macros/latex/contrib/cellspace (or browse the directory); catalogue entry
makecell.sty
macros/latex/contrib/makecell (or browse the directory); catalogue entry
tabls.sty
macros/latex/contrib/tabls (or browse the directory); catalogue entry

This answer last edited: 2011-05-02


Go to previous question, or next question

Go to FAQ home.

URL for this question: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=struttab

Comments, suggestions, or error reports? - see “how to improve the FAQ”.

This is FAQ version 3.27, released on 2013-06-07.