How can I make a table like the type in this image in LaTeX?

I'm trying to make a table like the one in following image in LaTeX

but I'm unsure how to go about it. I've been using the tabular environment from the booktabs package, but the following code doesn't produce the table correctly. There are breaks in the lines, the lines extend too far, etc.

\documentclass[10pt]{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{ccc|ccccccc}
&&&&&\multicolumn{5}{c}{Capacity j} \\
&&i&0&1&2&3&4&5&6\\
\midrule
&&0&0&0&0&0&0&0&0\\
$w_1 = 3$&$v_1 = 25$&1&0&0&0&25&25&25&25\\
$w_1 = 2$&$v_1 = 20$&2&0&0&20&25&25&45&45\\
\end{tabular}
\end{document}


This produces a table that looks like this:

I know my MWE isn't complete, but I included the necessary code to demonstrate the problems with my current table.

-
I actually think your version is much nicer. The break lends weight to the header (although perhaps you don't want this). –  naught101 Nov 5 '12 at 1:28

I'd use something like this:

\documentclass[10pt]{article}
\usepackage{array}

\begin{document}

\setlength\extrarowheight{3pt}
\noindent\begin{tabular}{>{$}c<{$}@{,\,}>{$}c<{$}c|ccccccc}
\multicolumn{2}{c}{} & & & \multicolumn{5}{c}{Capacity $j$} \\
\multicolumn{2}{c}{} & $i$ & 0 & 1 & 2 & 3 & 4 & 5 & 6 \\
\cline{3-10}
\multicolumn{2}{c}{} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
w_1 = 3 & v_1 = 25 & 1 & 0 & 0 & 0 & 25 & 25 & 25 & 25 \\
w_1 = 2 & v_1 = 20 & 2 & 0 & 0 & 20 & 25 & 25 & 45 & 45 \\
\end{tabular}

\end{document}


1. I didn't used the booktabs package, since it doesn't cooperate with vertical lines.
2. I used the >{...}, <{...} constructs provided by the array package to facilitate the inclusion of math mode for the first and second columns.
3. I used the @{...} construct to automatically include the comma between the first and the second columns.
4. I used \multicolumn to override the format specification for some columns.
5. I used \cline{i-j} (the equivalent in booktabs is \cmidrule) to obtain a horizontal line spanning from column i to column j.
6. \extrarowheight was used to increase the vertical space of rows; to keep this setting local, you can enclose the code inside braces or inside other construct forming a group (for example a table environment,in which case \noindent will be superfluous).
-
Excellent answer, and with explanations to boot. Thank you. –  Ricardo Altamirano Apr 17 '12 at 18:59