[Tex/LaTex] Table spacing, multi column

multicolumnspacingtables

I am trying to construct a table, but the spacing isn't balanced.

\documentclass{article}
\usepackage[english]{babel}
\usepackage{multirow}

\begin{document}
\begin{center}
\begin{tabular}{ |c|c|c|c|c|c|c|c|c|c| }

\hline
\multirow{2}{*}{Class} & \multicolumn{2}{c|}{Similarity Gibbs Sampling} & \multicolumn{2}{c|}{Hand Computatation} & \multicolumn{4}{c|}{Combination} & \multirow{2}{*}{Graph Cut(S)} \\ \cline{2-1} \cline{3-1} \cline{4-1} \cline{5-1} \cline{6-1} \cline{7-1} \cline{8-1} \cline{9-1}
& 0 & 1 & 0 & 1 & 1 & 2 & 3 & 4 & \\ \hline
${V_1}$ & 0.388 & 0.612 & 0.393 & 0.607 & 0 & 0 & 1 & 0 & 2 \\ \hline
${V_2}$ & 1 & 0 & 1 & 0 & 0 & 0 & 1 & 1 & 2 \\ \hline
${V_3}$ & 0 & 1 & 0 & 1 & 1 & 0 & 1 & 0 & 3 \\ \hline
${V_4}$ & 0.388 & 0.612 & 0.393 & 0.607 & 1 & 0 & 1 & 1 & 1 \\ \hline
%\cline{2-1} 
\end{tabular}
\end{center}
\end{document}

enter image description here

As you can see, the 3rd column and 5th column do not share the same spacing as 2nd and 4th respectively.

Best Answer

In addition to the issue with the widths of columns 3 and 5 not being the same as those of columns 2 and 4, respectively, I'd say your table has a second issue: The horizontal lines you're trying to draw between the first and second header rows touch each other and thus don't provide visual clues as to how the columns are grouped. (This is a shortcoming caused by the properties of \cline which can't be remedied easily short of using a different group of line-drawing commands -- see below for an alternative.)

  • To fix the first issue, you could use the tabularx package and its X column type to guarantee equal widths of columns 2 through 5. By default, material in a column of type X is set left-justified (ragged-right); in the example below I define a new column type, Y, which is a center-set version of X.

  • The second issue is best addressed, I believe, by using the line-drawing commands of the booktabs package. In particular, the command \cmidrule can serve to draw short "trimmed" horizontal lines that don't touch. Other benefits of using the rule-drawing comamnds of the booktabs package is that the spacing above and below the lines is much better than what you'll get with \hline and \cline and that the rules aren't all equally thick, making for a much more interesting-looking table.

enter image description here

\documentclass{article}
\usepackage{tabularx,booktabs}
  \newcolumntype{Y}{>{\centering\arraybackslash}X}
\usepackage[margin=1in]{geometry}  % choose page parameters best for your document
\begin{document}
\begin{table}
\begin{tabularx}{\textwidth}{@{} l *{4}{Y} *{5}{c} @{}}
\toprule
Class & 
\multicolumn{2}{c}{Similarity Gibbs Sampling} & 
\multicolumn{2}{c}{Hand Computation} & 
\multicolumn{4}{c}{Combination} & 
Graph Cut(S) \\ 
\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-9} % left- and right-trimming
& 0 & 1 & 0 & 1 & 1 & 2 & 3 & 4 & \\ 
\midrule
${V_1}$ & 0.388 & 0.612 & 0.393 & 0.607 & 0 & 0 & 1 & 0 & 2\\ 
${V_2}$ & 1 & 0 & 1 & 0 & 0 & 0 & 1 & 1 & 2 \\ 
${V_3}$ & 0 & 1 & 0 & 1 & 1 & 0 & 1 & 0 & 3 \\ 
${V_4}$ & 0.388 & 0.612 & 0.393 & 0.607 & 1 & 0 & 1 & 1 & 1\\ 
\bottomrule
\end{tabularx}
\end{table}
\end{document}
Related Question