Nice Tabular and Array Spacing in LaTeX
December 4, 2005 – 4:21 pmI have struggled for quite some time trying to find a nice way to space entries in the tabular or array environments in LaTeX. I am often in the situation where I have used a fraction in an entry, and the numerator is in contact with the upper horizontal rule and/or the denominator is in contact with the lower horizontal rule. For instance, I get a table that looks like

with the source code
\[
\begin{array}{ll}
\cline{1-2}
\mbox{In the interior} & \displaystyle
\phi_{i,j} = \frac{1}{4} \left( \phi_{i+1,j}
+ \phi_{i-1,j} + \phi_{i,j+1} + \phi_{i,j-1} \right) \\
\cline{1-2}
\mbox{On the left wall} & \displaystyle
\phi_{i,j} = \frac{1}{4} \left(
2 \phi_{i+1,j} + \phi_{i,j+1} + \phi_{i,j-1} \right) \\
\cline{1-2}
\mbox{On the right wall} & \displaystyle
\phi_{i,j} = \frac{1}{4} \left(
2\phi_{i-1,j} + \phi_{i,j+1} + \phi_{i,j-1} \right) \\
\cline{1-2}
\end{array}
\]
I recently solved my problems when I stumbled across the booktabs package for LaTeX. The author writes in the PDF documentation (version 1.61803)
The routines described below are to enable the easy production of tables such as should appear in published scientific books and journals.
The booktabs package has introduced me to commands such ad /toprule, /midrule, and /bottomrule, all of which produce nicely spaced horizontal rules that do not interfere with my table or array entries. I can get output that looks like

with the source code
\[
\begin{array}{ll}
\toprule
\mbox{In the interior} & \displaystyle
\phi_{i,j} = \frac{1}{4} \left( \phi_{i+1,j}
+ \phi_{i-1,j} + \phi_{i,j+1} + \phi_{i,j-1} \right) \\
\midrule
\mbox{On the left wall} & \displaystyle
\phi_{i,j} = \frac{1}{4} \left(
2 \phi_{i+1,j} + \phi_{i,j+1} + \phi_{i,j-1} \right) \\
\midrule
\mbox{On the right wall} & \displaystyle
\phi_{i,j} = \frac{1}{4} \left(
2\phi_{i-1,j} + \phi_{i,j+1} + \phi_{i,j-1} \right) \\
\bottomrule
\end{array}
\]
These commands work equally well with the tabular environment. The author is very particular, though, about a couple of rules he has outlined for tables: (1) never use vertical rules, and (2) never use double rules. The booktabs package will not allow you to create nice looking vertical rules (e.g. rules between columns in a table), but you can create double horizontal rules that look okay. This particular package has solved ninety percent of my table and array spacing problems in LaTeX.
9 Responses to “Nice Tabular and Array Spacing in LaTeX”
Latex? I was expecting a post on the UT-Colorado game, or the upcoming USC-UT national championship game. You disappoint me Jeff.
Oh, and I think some of your red font color bled into the rest of the text. Or at least that’s how it shows up on my end.
By Adam on Dec 4, 2005 at 4:55 pm
And the font color thing is very interesting. Firefox handles it as I would expect, but Opera has it bleed into the other text. I wonder why that is.
By jjk on Dec 4, 2005 at 5:12 pm
Okay, I just fixed the color bleeding issue. I had misused some tags in my post. Firefox suppressed the error; Opera exposed it.
By jjk on Dec 4, 2005 at 5:15 pm
So, Opera did what your webpage was telling it to and Firefox didn’t?
By Adam on Dec 5, 2005 at 12:33 am
Actually, no. I wasn’t telling the webpage to do anything in particular. A misuse of tags does not imply I was telling it to do one thing and it did another. In this case, a misuse of tags means that the tags that I used were nonsense.
Firefox was nice enough to realize it was an error and handle it gracefully. Opera didn’t know how to handle it, so it gave me garbage.
By jjk on Dec 5, 2005 at 9:11 am
Shoot.
Jeff (Firefox) - 1
Adam (Opera) - 0
By Adam on Dec 6, 2005 at 10:45 pm
I use Opera a little bit, and I actually got into using Opera because I found that it rendered one particular page much quicker than Firefox. That page? http://sportsillustrated.cnn.com
I don’t know how Firefox 1.5 handles that page yet, as the RPM has not been released to the Fedora Core repositories I use. That problem is unique to Linux, however. Firefox on my iBook loads SportsIllustrated fine, but for whatever reason, the Linux version is terribly slow with it.
It’s interesting to see how many differences there can be in a Web browsing experience that is supposed to more or less browser-neutral.
By jjk on Dec 6, 2005 at 11:31 pm
Ahh, well, if you use Opera occasionally, then I’ll have to give you a copy of my settings. I’ve been using opera pretty much since I got to Caltech and have slowly refined the settings. I think I’ve got most everything tricked out the way I want them now.
By Adam on Dec 7, 2005 at 5:30 pm
That’s pretty cool. I am still much the Opera neophyte. I just figured out a couple of weeks ago how to change they keyboard shortcuts so I could use Ctrl-t to open a new tab.
Oh, and there is one feature of GMail that I notice doesn’t seem to work with the way I have set up Opera. In Firefox, I can type the first few letters of a person’s first name, last name, or email address, and some suggestions will pop up from my Contacts list. In Opera, no such suggestion box appears. Do you know why that is?
By jjk on Dec 8, 2005 at 8:10 am