I suppose I should start with the subject that made me start this blog in the first place: formatting tables. Now I'm sure this is the first in a series of posts on tables, as anyone who has worked with them knows how finicky they can be.

The two aspects of tables I'm explaining today are the column and row separation values. For those that are looking for quick fixes, I'll give them to you right away:

Column Width: \tabcolsep

Usage: \renewcommand\tabcolsep{6pt}

Explanation: tabcolsep is HALF the space between two columns. Default value is 6pt

Row Height: \arraystretch

Usage: \renewcommand\arraystretch{1}

Explanation: arraystretch is a FACTOR representing the distance between two rows. Default is 1

The two variables are manipulated in different ways: tablecolsep is a unit, so it can be specified in a variety of ways (pt, ex, em, etc...) which arraystretch is a factor, so it has no units.

The code demonstrates how to manipulate the variables, using beamer slides.

\documentclass{beamer}

\begin{document}

\begin{frame}[fragile]

\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}\hline

1 & 2 &3 &4 &5 &6 &7 &8 &9 & a &b &c &d &e &f \\\hline

Wide Column & & & & & & & & & & & & & & \\\hline

\end{tabular}

\renewcommand\arraystretch{1.1}

\renewcommand\tabcolsep{3pt}

\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}\hline

1 & 2 &3 &4 &5 &6 &7 &8 &9 & a &b &c &d &e &f \\\hline

Wide Column & & & & & & & & & & & & & & \\\hline

\end{tabular}

\renewcommand\arraystretch{0}

\renewcommand\tabcolsep{0pt}

\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}\hline

1 & 2 &3 &4 &5 &6 &7 &8 &9 & a &b &c &d &e &f \\\hline

Wide Column & & & & & & & & & & & & & & \\\hline

\end{tabular}

\renewcommand\arraystretch{2}

\renewcommand\tabcolsep{6pt}

\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}\hline

1 & 2 &3 &4 &5 &6 &7 &8 &9 & a &b &c &d &e &f \\\hline

Wide Column & & & & & & & & & & & & & & \\\hline

\end{tabular}

\end{frame}

\end{document}

Which produces these slides

## Thursday, October 30, 2008

Subscribe to:
Post Comments (Atom)

Thank you very much for your tip! I was looking all the net and your post was just what i needed, easy and clear.

ReplyDeleteGreetings from Catalonia!

This comment has been removed by a blog administrator.

ReplyDeleteI spent half-hour looking for this simple trick. Thank you!

ReplyDeleteHelped me, too. Thanks!

ReplyDeleteThank you so much!!!!

ReplyDeleteThanks! Helped a lot.

ReplyDeleteFor some reason, \renewcommand\tabcolsep{4pt} did not work. I'm not sure as to the whys, but \setlength{\tabcolsep}{4pt} does the trick.

ReplyDeleteRelated to the comment by Bernhard Schenkenfelder, \tabcolsep is a length, not a command. Please use \setlength to adjust its value rather than \renewcommand. I hope you'll consider editing your post to correct this, especially since this page is one of the top hits for searches like "\tabcolsep default value". Thanks!

ReplyDelete