# Making an odd shaped table

I'm trying to make a table that looks like this:

               +--------------+
|   Class 1    |
+--------------+
|   A  |   B   |
+---------+----+------+-------+
|         | C  |   a  |   b   |
| Class 2 +----+------+-------+
|         | D  |   c  |   d   |
+---------+----+------+-------+


There are many things wrong with my code. First is the way that the word span appears in front of the \multicolumn{2}{|c|}{{\textbf{Class 1}}} entry (which doesn't span the line). Second the line between C and D goes all the way through class 2. I don't know how to get rid of the lines in the top right. It's a real mess, what am I doing wrong? Apologies for the not-very specific question.

\begin{tabular}{|r|c||c|c|}
\hline
\multicolumn{2}{c}{} & \multicolumn{2}{|c|}{{\textbf{Class 1}}} \\
\multicolumn{2}{c}{} & A & B \\
\multirow{2}{*}{{\textbf{Class 2}}}
& C & a & b \\
\hline
& D & c & d \\
\hline
\end{tabular}

-
Cool, I will do –  Lucas Jul 7 '12 at 11:30

I stole most of the answer from here , but I think this is what you want

\begin{tabular}{rc|c|c|}
\cline{3-4}
& & \multicolumn{2}{|c|}{{\textbf{Class 1}}} \\
\cline{3-4}
& & A & B \\
\hline
\multicolumn{1}{|c|}{\multirow{2}{*}{{\textbf{Class 2}}}}& C & a & b \\
\cline{2-4}
\multicolumn{1}{|c|}{}& D & c & d \\
\hline
\end{tabular}


-

If you are typesetting sort of Cayley table, then I think the approach by Rick de Groot is good. If it's more a text table, you might use the package booktabs to enhance the look your table a little, omitting the verical lines and adding some vertical space:

\documentclass{article}

\usepackage{booktabs}

\begin{document}

\begin{tabular}{rccc}
\toprule
& & \multicolumn{2}{c}{{\textbf{Class 1}}}
\\\cmidrule{3-4}
& & A & B
\\\midrule[\heavyrulewidth]
\textbf{Class 2}
& C & a & b
\\\cmidrule{2-4}
& D & c & d
\\\bottomrule
\end{tabular}

\end{document}


Variant two: As Jake pointed out, this solution cannot be used with the multirow package to center Class 2. More tweaking using calc package can be done:

\documentclass{article}

\usepackage{booktabs}
\usepackage{calc}

\begin{document}

\begin{tabular}{rccc}
\toprule
& & \multicolumn{2}{c}{{\textbf{Class 1}}}
\\\cmidrule{3-4}
& & A & B
\\\midrule[\heavyrulewidth]
\begingroup\makeatletter
\setlength{\@tempdima}{\totalheightof{\strut}}
\smash{\raisebox{-0.5\@tempdima-0.5\aboverulesep-0.5\belowrulesep-0.5\lightrulewidth}{%
\textbf{Class 2}%
}}
\endgroup
& C & a & b
\\\cmidrule{2-4}
& D & c & d
\\\bottomrule
\end{tabular}

\end{document}


-
Not what I was thinking. But it does look nicer –  Lucas Jul 7 '12 at 11:58