Padding at the top of a table cell in LaTeX

One way to get better-looking tables while still using vertical rules is to insert "struts" in selected rows to improve the spacing around horizontal lines. (This was suggested by Claudio Beccari in a piece published in 1993 in TeX and TUG News.) The idea is to insert "top struts" in rows that have an \hline above them, a "bottom strut" in rows that have an \hline below them, and both top and bottom struts in rows -- such as header rows -- that have \hlines both above and below them:

enter image description here

\documentclass{article}
% Define "struts" as suggested by Claudio Beccari in
% a piece in TeX and TUG News, Vol. 2, 1993.
\newcommand\Tstrut{\rule{0pt}{2.6ex}}       % "top" strut
\newcommand\Bstrut{\rule[-0.9ex]{0pt}{0pt}} % "bottom" strut
\newcommand{\TBstrut}{\Tstrut\Bstrut} % top&bottom struts
\begin{document}
\begin{tabular}{|l|l|l|}
  \hline
  A  & B  & C \TBstrut\\ % top and bottom struts
  \hline
  A1 & B1 & C1 \Tstrut\\ % top strut only
  A2 & B2 & C2 \Bstrut\\ % bottom strut only
  \hline
\end{tabular}
\end{document}

That said, I believe one is more likely to produce good-looking tables if one (i) doesn't use vertical rules at all and (ii) uses the booktabs package and its commands \toprule, \midrule, and \bottomrule instead of \hline to create horizontal lines. Note that the \[xxx]rule lines don't all have the same widths and that there's good spacing around them.

enter image description here

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{lll}
  \toprule
  A  & B  & C \\
  \midrule
  A1 & B1 & C1 \\
  A2 & B2 & C2 \\
  \bottomrule
\end{tabular}
\end{document}

You can add extra vertical spacing at the top using \extrarowheight from the array package; the following example presents three options: the first one, your table; the second one, the same table, but setting \extrarowheight to 2pt, adding 2pt to every row height, but keeping the depth unchanged; the third option, using the booktabs package (spacing is much better now by default, but no vertical rules):

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}

\begin{document}

\noindent\begin{tabular}{|l|l|l|}
  \hline
  A  & B  & C \\
  \hline
  A1 & B1 & C1 \\
  \hline
  A2 & B2 & C2 \\
  \hline
\end{tabular}

\vspace{1cm}

{
\setlength\extrarowheight{2pt}
\noindent\begin{tabular}{|l|l|l|}
  \hline
  A  & B  & C \\
  \hline
  A1 & B1 & C1 \\
  \hline
  A2 & B2 & C2 \\
  \hline
\end{tabular}
}

\vspace{1cm}

\noindent\begin{tabular}{lll}
  \toprule
  A  & B  & C \\
  \midrule
  A1 & B1 & C1 \\
  A2 & B2 & C2 \\
  \bottomrule
\end{tabular}

\end{document}

enter image description here


I'd suggest cals package, which is vebose but makes many things automatically:

simple cals table

\documentclass{article}
\usepackage{cals}
\begin{document}
\begin{calstable}
\colwidths{{1cm}{1cm}{1cm}}
\brow \cell{A} \cell{B} \cell{C}  \erow
\brow \cell{A1}\cell{B1}\cell{C1} \erow
\brow \cell{A2}\cell{B2}\cell{C2} \erow
\end{calstable}
\end{document}

Tags:

Tables