[Tex/LaTex] Too long vertical lines in table

rulestables

Ok, I've looked at this code too long and need some fresh eyes and ideas.

Question: Why do I get too long vertical lines on my LaTeX table?

Please note that I've not experiencing any problems with the above code on online compilers such as http://docs.latexlab.org/docs

I'm using the texi2pdf in order to compile my document on Mac OSX Snow Leopard.

Code:

\begin{table}[h]
    \begin{tabular}{|l|l|l|l|l|l|l|l|l|l|} 
    \hline
        ContainsPrize & \multicolumn{3}{|c|}{A} & \multicolumn{3}{|c|}{B} & \multicolumn{3}{|c|}{C} \\ \hline
        MyChoice      & A   & B & C & A & B   & C & A & B & C   \\ \hline
        openA         & 0   & 0 & 0 & 0 & 0.5 & 1 & 0 & 1 & 0.5 \\
        openB         & 0.5 & 0 & 1 & 0 & 0   & 0 & 1 & 0 & 0.5 \\
        openC         & 0.5 & 1 & 0 & 1 & 0.5 & 0 & 0 & 0 & 0   \\
    \hline
    \end{tabular}
    \caption{A nice caption text here...}
 \end{table}

Which generates:

table with oversized lines

Any ideas? Buggy compiler? Alternatives?

Best Answer

This is tricky. What you have is actually a 3-dimensional table that you want to represent as a 2-dimensional image on the page. There are 3 input values and 3³ = 27 output values.

I think what you want here is Occam's Razor...

  • Right-align first column
  • Pad inner columns (groups of 3) with extra horizontal space
  • Write 0.5 as fraction ½
  • Throw in some double-stroked rules (I know that sounds crazy, since it's a reverse-simplification)
  • Then remove as much as possible and see where that leads...

For example:

You could even play around with removing the vertical rules entirely and replacing them with vertical whitespace:

Maybe even rewrite the zeros as dashes, if the data still happens to make sense that way...

Note: I'm not sure that the latter two forms are actually clearer, even though they are less complex for the eyes to process. The reason is that, as mentioned earlier, this is inherently a 3-dimensional table with 27 values. The final two forms — which use horizontal rules only — muddy the dimensionality as they lead the eye to scan left-to-right. Compare and contrast this with the second form, in which the double-stroked rules serve to separate the three 3x3 grids from the labels above and to the left.

As much as I dislike vertical rules and double-stroked rules in general, I think the second form might actually be the clearest of the five shown here. I'd be curious to hear your thoughts.

In any event, below is the LaTeX source for the samples above.

 \documentclass{article}
 \usepackage{booktabs}
 \usepackage{nicefrac}
 \newcommand{\half}{\nicefrac{1}{2}}
 \begin{document}

 \begin{tabular}{|r||ccccc|ccccc|ccccc|}
 \hline
 ContainsPrize &&& A &&&&& B &&&&& C &&\\
 \hline
 MyChoice && A & B & C &&& A & B & C &&& A & B & C &\\
 \hline\hline
 openA &&     0 & 0 & 0 &&& 0 & \half & 1 &&& 0 & 1 & \half &\\
 openB && \half & 0 & 1 &&& 0 &     0 & 0 &&& 1 & 0 & \half &\\
 openC && \half & 1 & 0 &&& 1 & \half & 0 &&& 0 & 0 &     0 &\\
 \hline
 \end{tabular}

 \vskip 3em

 \begin{tabular}{r||ccccc|ccccc|ccccc}
 ContainsPrize &&& A &&&&& B &&&&& C &&\\
 \hline
 MyChoice && A & B & C &&& A & B & C &&& A & B & C &\\
 \hline\hline
 openA &&     0 & 0 & 0 &&& 0 & \half & 1 &&& 0 & 1 & \half &\\
 openB && \half & 0 & 1 &&& 0 &     0 & 0 &&& 1 & 0 & \half &\\
 openC && \half & 1 & 0 &&& 1 & \half & 0 &&& 0 & 0 &     0 &\\
 \end{tabular}

 \vskip 3em

 \begin{tabular}{r|ccccc|ccccc|ccccc}
 ContainsPrize &&& A &&&&& B &&&&& C &&\\
 \hline
 MyChoice && A & B & C &&& A & B & C &&& A & B & C &\\
 \hline
 openA &&     0 & 0 & 0 &&& 0 & \half & 1 &&& 0 & 1 & \half &\\
 openB && \half & 0 & 1 &&& 0 &     0 & 0 &&& 1 & 0 & \half &\\
 openC && \half & 1 & 0 &&& 1 & \half & 0 &&& 0 & 0 &     0 &\\
 \end{tabular}

 \vskip 4em

 \setlength{\tabcolsep}{.5em}
 \begin{tabular}{r c ccc c ccc c ccc}
 \toprule
 ContainsPrize &~~~~~~&~ & A & ~&~~~& ~ &     B & ~&~~~& ~ & C &     ~\\
 \midrule
 MyChoice      &&      A & B & C  &&  A &     B & C  &&  A & B &     C\\
 \toprule
 openA         &&      0 & 0 & 0  &&  0 & \half & 1  &&  0 & 1 & \half\\
 openB         &&  \half & 0 & 1  &&  0 &     0 & 0  &&  1 & 0 & \half\\
 openC         &&  \half & 1 & 0  &&  1 & \half & 0  &&  0 & 0 &     0\\
 \bottomrule
 \end{tabular}

 \vskip 4em

 \setlength{\tabcolsep}{.5em}
 \begin{tabular}{r c ccc c ccc c ccc}
 \toprule
 ContainsPrize &~~~~~~&~ & A & ~&~~~& ~ &     B & ~&~~~& ~ & C &     ~\\
 \midrule
 MyChoice      &&      A & B & C  &&  A &     B & C  &&  A & B &     C\\
 \toprule
 openA         &&     -- & -- & --  && -- & \half &  1 && -- &  1 & \half\\
 openB         &&  \half & -- &  1  && -- &    -- & -- &&  1 & -- & \half\\
 openC         &&  \half &  1 & --  &&  1 & \half & -- && -- & -- &    --\\
 \bottomrule
 \end{tabular}

 \end{document}
Related Question