4

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}
Werner
  • 603,163
blehman
  • 207

2 Answers2

7

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.

Werner
  • 603,163
2

You can try the cellspace package, that defines minimal vertical spacing above and below cells in columns with specifier prefixed with the letter S. If one uses the siunitx package which also uses the letter S, the prefix is replaced with the letter C:

%%%%%%%%%%
\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, booktabs}
\usepackage{siunitx}
\sisetup{table-format =4.0,table-number-alignment = center}
\usepackage{cellspace}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}

\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}{With \texttt{cellspace}}
\centering
\begin{tabular}{ClS[table-format=5.0]SSS[table-format=3.0]S[table-format=3.0] S}
  \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} 

enter image description here

Bernard
  • 271,350