18

This question already has an answer here:

I have a simple LaTeX tabular table:

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

the rendered table

Now the padding at the top of the cells is much smaller than the padding at the bottom, I guess because space for descenders is reserved. It makes the text look unaligned. How do I add some padding at the top of the table cells? I tried \arraystretch but it also adds padding at the bottom.

marked as duplicate by Werner, Mensch, clemens, Stefan Kottwitz Aug 4 '13 at 14:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

19

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}
  • Of course... somehow my brain forgot about struts (a common tool in TeX) as soon as I was trying to use LaTeX. I'm not sure if it works with p columns, but I will see. – AndreKR Aug 3 '13 at 22:29
  • @AndreKR - Top struts should work just fine with p-type columns. – Mico Aug 4 '13 at 0:23
  • They do, wonderful. :) – AndreKR Aug 4 '13 at 14:26
  • \toprule did the job for me! – Sina Madani Feb 26 '18 at 17:06
14

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

3

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}

Not the answer you're looking for? Browse other questions tagged or ask your own question.