Generalvertical line problem with tables and multicolumn (MWE)

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
PGScooter
Posts: 31
Joined: Mon Jul 14, 2008 2:47 pm

vertical line problem with tables and multicolumn (MWE)

Post by PGScooter »

Hi

I cannot seem to get my vertical lines to work correctly. One goes outside the table and another doesn't quite make it up to the top. Is this because I am using \multicolumn? Is there any quick fix for this? thanks!

Here is an example of my problem:

Code: Select all

\documentclass{article}
\begin{document}
\begin{table}[!ht]\caption{Comparison of Groups With and Without Transfer Data}\label{transfercomp}
\fbox{
\begin{tabular}{l|cc|c}
	&\multicolumn{2}{c}{Total}\\
	\textbf{ }&\textbf{w/ T}&\textbf{w/o T}&\textbf{Control}\\
\hline\hline
\vspace{-.2cm}&&&\\
number of obs.&&&\\
study abroad&.836&1&0\\

\end{tabular}}
\end{table}

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

vertical line problem with tables and multicolumn (MWE)

Post by phi »

Don't combine \fbox and tabulars, the spacing won't be correct. If you use \multicolumn, you have to repeat any rule specifications. You should ensure that you always have the same number of (possibly empty) cells in each row. The following looks slightly better, but be aware that in professional tables there are no vertical or double lines at all:

Code: Select all

\begin{tabular}{|l|cc|c|}
\hline
   &\multicolumn{2}{|c|}{Total}&\\
   &\textbf{w/ T}&\textbf{w/o T}&\textbf{Control}\\
\hline\hline
number of obs.&&&\\
study abroad&.836&1&0\\
\hline
\end{tabular}
PGScooter
Posts: 31
Joined: Mon Jul 14, 2008 2:47 pm

Re: vertical line problem with tables and multicolumn (MWE)

Post by PGScooter »

thanks Phi, it works great

I have read all over the place that one should NEVER use vertical lines. I understand this general rule, but it must have some exceptions, right?

What would be the recommended way to display my table? I have a table with three categories and within each of those, 2 sub-categories (the same subcategories for all three categories). I want to display the sub-categories side by side so that the reader can easily compare the differences in the numbers.

To me, the vertical lines guide the readers to the numbers that they should be comparing. They give direction, in my opinion.

Is there a better way for such a setup?

Thanks
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

vertical line problem with tables and multicolumn (MWE)

Post by phi »

PGScooter wrote:I have read all over the place that one should NEVER use vertical lines. I understand this general rule, but it must have some exceptions, right?
According to Simon Fear, author of the booktabs package, there are no exceptions. Of course, nothing stops you from breaking rules, but you should be aware why you break it.
PGScooter wrote:What would be the recommended way to display my table? I have a table with three categories and within each of those, 2 sub-categories (the same subcategories for all three categories). I want to display the sub-categories side by side so that the reader can easily compare the differences in the numbers.
I'm not an expert in typography, and I'd rather recommend reading the booktabs manual for some explanation and guidelines. For example, you can group the categories using \cmidrule.
Here is a FAQ entry related to this discussion:
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=destable
PGScooter
Posts: 31
Joined: Mon Jul 14, 2008 2:47 pm

Re: vertical line problem with tables and multicolumn (MWE)

Post by PGScooter »

thank you for the links!

that was some good reading material. I have been persuaded to forgo the vertical lines. booktabs looks like a package with which I should become familiar.

thanks
Post Reply