[Tex/LaTex] Vertical spacing options in tables built under the tabularx package

spacingtablestabularx

Goals:

  • Add a space above and below the text line containing the Table 1's column headers.
  • Add a space below the second hline.
  • Add a space above the third hline.

The code below contains the original table (#1) along with several failed attempts (#2,#3,#4)to accomplish the above mentioned goals.

Additional details:

  1. I am using pdflatex to render the .tex file

  2. I am using the tabularx package.

  3. I am using xtable() in R to build the .tex for these tables, but it's not necessary to answer the question with xtable options since I can edit the .tex after using R.

Any help would be greatly appreciated. Suggestions?

enter image description here

enter image description here

%%%%%%%%%%
\documentclass{article}
\usepackage{graphicx}
\usepackage[sc]{mathpazo}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage[labelfont=sf,hypcap=false,format=hang,width=1\columnwidth]{caption}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=3cm,rmargin=3cm}
\usepackage{longtable}
\usepackage{tabularx}
\usepackage{array}
\begin{document}
%%%%%%%%%%

\title{Understanding Tables: Vertical Spacing}
\author{Brian}
\maketitle
This report is designed to be a quick resource for editing the vertical spacing in 'tabularx' tables. \\

\begin{table}[ht]
\captionof{table}{Original}
\centering
\begin{tabular}{lrrrrrr}
  \hline
Type & Total & Mean & Median & Stdev & Min & Max \\
  \hline
Test1 & 490 &  15 &   8 &  24 &   1 & 115 \\
  Test2 & 52610 & 1697 & 1620 & 430 & 920 & 2850 \\
   \hline
\end{tabular}
\end{table}

{\renewcommand{\arraystretch}{2}%
\begin{table}[ht]
\captionof{table}{Spaceing stretched above and below ALL cells}
\centering
\begin{tabular}{lrrrrrr}
  \hline
Type & Total & Mean & Median & Stdev & Min & Max \\
  \hline
Test1 & 490 &  15 &   8 &  24 &   1 & 115 \\
  Test2 & 52610 & 1697 & 1620 & 430 & 920 & 2850 \\
   \hline
\end{tabular}
\end{table}}

\begin{table}[ht]
\captionof{table}{Spacing streched ABOVE header}
\centering
\begin{tabular}{lrrrrrr}
  \hline
\rule{0pt}{4ex}Type & Total & Mean & Median & Stdev & Min & Max \\
  \hline
Test1 & 490 &  15 &   8 &  24 &   1 & 115 \\
  Test2 & 52610 & 1697 & 1620 & 430 & 920 & 2850 \\
   \hline
\end{tabular}
\end{table}


\begin{table}[ht]
\captionof{table}{Spacing streched ABOVE ALL cells}
\centering
\setlength\extrarowheight{14pt}
\begin{tabular}{lrrrrrr}
  \hline
Type & Total & Mean & Median & Stdev & Min & Max \\
  \hline
Test1 & 490 &  15 &   8 &  24 &   1 & 115 \\
  Test2 & 52610 & 1697 & 1620 & 430 & 920 & 2850 \\
   \hline
\end{tabular}
\end{table}

\end{document}

Best Answer

Your approach here (in terms of horizontal rules) matches that of what is suggested by booktabs. Here's what I would use:

enter image description here

\documentclass{article}
\usepackage[sc]{mathpazo}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage[labelfont=sf,hypcap=false,format=hang,width=\columnwidth]{caption}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=3cm,rmargin=3cm}
\usepackage{tabularx,booktabs}
\begin{document}

\begin{table}[ht]
  \caption{Original}
  \centering
  \begin{tabular}{lrrrrrr}
    \hline
    Type & Total & Mean & Median & Stdev & Min & Max \\
    \hline
    Test1 & 490 &  15 &   8 &  24 &   1 & 115 \\
    Test2 & 52610 & 1697 & 1620 & 430 & 920 & 2850 \\
    \hline
  \end{tabular}
\end{table}


\begin{table}[ht]
  \renewcommand{\arraystretch}{1.2}%
  \caption{\texttt{booktabs} version}
  \centering
  \begin{tabular}{l *{6}{r} }
    \toprule
    Type & Total & Mean & Median & Stdev & Min & Max \\
    \midrule
    Test1 & 490 &  15 &   8 &  24 &   1 & 115 \\
    Test2 & 52610 & 1697 & 1620 & 430 & 920 & 2850 \\
    \bottomrule
  \end{tabular}
\end{table}

\end{document}

booktabs' \toprule, \midrule and \bottomrule inserts additional (white) rules to separate the text around these rules a little. This, together with the use of an increased \arraystretch seems sufficient to obtain a breathable result.

Related Question