[OS X TeX] vertical space in tables

Bruno Voisin bvoisin at mac.com
Sun Apr 22 11:20:03 EDT 2007

Le 21 avr. 07 à 23:11, McGarry Vince a écrit :

> On Apr 21, 2007, at 2:05 PM, Themis Matsoukas wrote:
>
>> Is there a simple way to increase the vertical spacing in tabular
>> and array environments? My solution is to use a rule with zero
>> width, for example
>>
>> \begin{array}{cc}
>> \rule[-7.5pt]{0pt}{20pt} A & B \\
>> \rule[-7.5pt]{0pt}{20pt} C & D \\
>> etc
>> \end{array}
>>
>> but it takes some tweaking with the numbers to get it to work nicely.
>
> I usually use \renewcommand{\arraystretch}{factor} and am satisfied
> with the results.

LaTeX's way of constructing tables is, like many things TeX, oriented
towards content made exclusively of plain text, and feels more and
more out-of-touch with the content of modern documents.

Tables are constructed row by row, and the height of each row is
defined by inserting a strut in each row entry, the default
definition of the strut being (from latex.ltx):

\setbox\strutbox\hbox{%
\vrule\@height.7\baselineskip
\@depth.3\baselineskip
\@width\z@}%

namely to extend 0.7 times the interline space above the baseline and
0.3 times the interline space below this baseline.

When each row entry has a vertical extent smaller than that of the
strut, the row height and depth are defined by the strut. So good for
textual content, the use of the struts ensuring even spacing of the
rows and the height/depth ratio of the strut corresponding to that of
plain text usually (in the Latin alphabet, that is).

When a row entry (for example an image or an equation) has height or
depth larger than that of the strut, then these natural dimensions
take over and the inter-row space is modified accordingly. A
disastrous consequence, however, is that there remains no vertical
space between the rows.

LaTeX has made provision for this situation, by allowing the user to
adjust the \arrowstretch, which is 1 by default and multiplies the
height and depth of the strut. This is a less than ideal situation:
when enlarging the \arrowstrech:

- The height/depth ratio for each row will remain 7/3, that of the
strut, meaning that an equation, for example, won't be centered
vertically within the row.

- Each and every row of the table will have the same vertical size,
even if there is only one row which is much bigger than the other.
The result will be most rows with lots of blank vertical space, and
one big overcrowded row.

For these reasons I tend to bypass completely LaTeX's table
construction model, by:

- Setting the height and depth of the strut to 0, as in:

\sbox{\strutbox}{\rule{0pt}{0pt}}

- Inserting vertical space manually between the content of the rows
and their borders, as in:

\\[\smallskipamount]
\hline
\\[\smallskipamount]

This mimicks the way tables are constructed cell by cell in
spreadsheets and in the HTML language, by considering the content of
each cell, defining its horizontal and vertical alignment within the
cell, and then inserting "padding" around it (namely space between
this content and each border of the cell).

Following is an example showing these concepts in action:

(1) LaTeX's default output.

(2) Output obtained by setting \arrowstretch to 2.2.

(3) Output obtained by setting the strut dimensions to 0.

(4) Output obtained by setting the strut dimensions to 0, then
inserting inter-row space manually.

Bruno Voisin

%%%%%%%% Beginning of example
\documentclass[12pt]{article}
\usepackage{amsmath}
\DeclareMathOperator{\Pf}{Pf}

\begin{document}

\centering

\begingroup
\begin{tabular}{|c|c|}
\hline
$f(x)$ &
$\displaystyle\int_{-\infty}^\infty f(x)\mathrm{e}^{-\mathrm{i} kx}\,\mathrm{d}x$ \\
\hline\hline
$(x+\mathrm{i}0)^{-\mu} \quad \text{($\mu \ne -n$)}$ &
$\displaystyle2\pi\mathrm{e}^{-\mathrm{i}\mu\pi/2}H(k)\frac{k^ {\mu-1}}{\Gamma(\mu)}$ \\
\hline
$x^n$ &
$2\pi\mathrm{i}^n\delta^{(n)}(k)$ \\
\hline
$x^n\bigl[\psi(n+1)+\mathrm{i}\tfrac{1}{2}\pi-\ln(x+\mathrm{i}0) \bigr]$ &
$2\pi\mathrm{i}^{-n}n!\Pf[H(k)k^{-(n+1)}]$ \\
\hline
\end{tabular}
\endgroup

\bigskip

\begingroup
\renewcommand{\arraystretch}{2.2}
\begin{tabular}{|c|c|}
\hline
$f(x)$ &
$\displaystyle\int_{-\infty}^\infty f(x)\mathrm{e}^{-\mathrm{i} kx}\,\mathrm{d}x$ \\
\hline\hline
$(x+\mathrm{i}0)^{-\mu} \quad \text{($\mu \ne -n$)}$ &
$\displaystyle2\pi\mathrm{e}^{-\mathrm{i}\mu\pi/2}H(k)\frac{k^ {\mu-1}}{\Gamma(\mu)}$ \\
\hline
$x^n$ &
$2\pi\mathrm{i}^n\delta^{(n)}(k)$ \\
\hline
$x^n\bigl[\psi(n+1)+\mathrm{i}\tfrac{1}{2}\pi-\ln(x+\mathrm{i}0) \bigr]$ &
$2\pi\mathrm{i}^{-n}n!\Pf[H(k)k^{-(n+1)}]$ \\
\hline
\end{tabular}
\endgroup

\bigskip

\begingroup
\sbox{\strutbox}{\rule{0pt}{0pt}}
\begin{tabular}{|c|c|}
\hline
$f(x)$ &
$\displaystyle\int_{-\infty}^\infty f(x)\mathrm{e}^{-\mathrm{i} kx}\,\mathrm{d}x$ \\
\hline\hline
$(x+\mathrm{i}0)^{-\mu} \quad \text{($\mu \ne -n$)}$ &
$\displaystyle2\pi\mathrm{e}^{-\mathrm{i}\mu\pi/2}H(k)\frac{k^ {\mu-1}}{\Gamma(\mu)}$ \\
\hline
$x^n$ &
$2\pi\mathrm{i}^n\delta^{(n)}(k)$ \\
\hline
$x^n\bigl[\psi(n+1)+\mathrm{i}\tfrac{1}{2}\pi-\ln(x+\mathrm{i}0) \bigr]$ &
$2\pi\mathrm{i}^{-n}n!\Pf[H(k)k^{-(n+1)}]$ \\
\hline
\end{tabular}
\endgroup

\bigskip

\begingroup
\sbox{\strutbox}{\rule{0pt}{0pt}}
\begin{tabular}{|c|c|}
\hline
& \\[\smallskipamount]
$f(x)$ &
$\displaystyle\int_{-\infty}^\infty f(x)\mathrm{e}^{-\mathrm{i} kx}\,\mathrm{d}x$ \\
& \\[\smallskipamount]
\hline\hline
& \\[\smallskipamount]
$(x+\mathrm{i}0)^{-\mu} \quad \text{($\mu \ne -n$)}$ &
$\displaystyle2\pi\mathrm{e}^{-\mathrm{i}\mu\pi/2}H(k)\frac{k^ {\mu-1}}{\Gamma(\mu)}$ \\
& \\[\smallskipamount]
\hline
& \\[\smallskipamount]
$x^n$ &
$2\pi\mathrm{i}^n\delta^{(n)}(k)$ \\
& \\[\smallskipamount]
\hline
& \\[\smallskipamount]
$x^n\bigl[\psi(n+1)+\mathrm{i}\tfrac{1}{2}\pi-\ln(x+\mathrm{i}0) \bigr]$ &
$2\pi\mathrm{i}^{-n}n!\Pf[H(k)k^{-(n+1)}]$ \\
& \\[\smallskipamount]
\hline
\end{tabular}
\endgroup

\end{document}
%%%%%%%% End of example