[Tex/LaTex] Problem with multirow and table cell borders

multicolumnmultirowtables

I'm pulling my hair with the rendering of table cell borders when using multirow and multicol. In the below example, the double-lines in the table's "header" do not extend to the table top, and even more annoying, there is a gap in the top-right corner of the table. Any clues?

\documentclass{article}
\usepackage[utf8x]{inputenc}
\usepackage{multirow}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\begin{tabular}{|l|c||c|c|c|c||c|c|c|c|} \hline \\
\multirow{2}{*}{} & \multirow{2}{*}{\rotatebox{90}{Target}} & \multicolumn{4}{|c||}{Banana} & \multicolumn{4}{|c|}{Pear} \\
& & \rotatebox{90}{Apple 1} & \rotatebox{90}{Apple 2} & \rotatebox{90}{Apple 3} & \rotatebox{90}{Apple 4} & \rotatebox{90}{Apple 1} & \rotatebox{90}{Apple 2} & \rotatebox{90}{Apple 3} & \rotatebox{90}{Apple 4} \\
    \hline
Apple 1 & $+$ &     & $*$ & $*$ & $*$ & $+$ &     &     &     \\ \hline
Apple 2 & $+$ & $*$ &     & $*$ & $*$ &     & $+$ &     &     \\ \hline
Apple 3 & $+$ & $*$ & $*$ &     & $*$ &     &     & $+$ &     \\ \hline
Apple 4 & $+$ & $*$ & $*$ & $*$ &     &     &     &     & $+$ \\ \hline
\end{tabular}
\end{figure}
\end{document}

enter image description here

Best Answer

Here's an improved alternative:

enter image description here

\documentclass{article}
\usepackage{multirow}% http://ctan.org/pkg/multirow
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\begin{document}
\begin{tabular}{|l|c||*{4}{c|}|*{4}{c|}} \hline
\multirow{2}{*}{} & \multirow{2}{*}[-1em]{\rotatebox{90}{Target}} & \multicolumn{4}{|c||}{Banana} & \multicolumn{4}{|c|}{Pear} \\
& & \rotatebox{90}{Apple 1} & \rotatebox{90}{Apple 2} & \rotatebox{90}{Apple 3} & \rotatebox{90}{Apple 4} & \rotatebox{90}{Apple 1} & \rotatebox{90}{Apple 2} & \rotatebox{90}{Apple 3} & \rotatebox{90}{Apple 4} \\
    \hline
Apple 1 & $+$ &     & $*$ & $*$ & $*$ & $+$ &     &     &     \\ \hline
Apple 2 & $+$ & $*$ &     & $*$ & $*$ &     & $+$ &     &     \\ \hline
Apple 3 & $+$ & $*$ & $*$ &     & $*$ &     &     & $+$ &     \\ \hline
Apple 4 & $+$ & $*$ & $*$ & $*$ &     &     &     &     & $+$ \\ \hline
\end{tabular}
\end{document}

You've inserted an additional row in the very first line using \hline \\. I've just removed the \\ and used some fine-tuning in the \multirow{<rows>}{<width>}[<fine-tune>]{<stuff>}. That is, pushed the content down 1em.

If you really want the empty row (for spacing), you need to complete the row with empty cells in order to have the vertical rules be placed correctly. In that sense, the following provides what you're after:

%...
\begin{tabular}{|l|c||*{4}{c|}|*{4}{c|}} \hline
& & \multicolumn{4}{c||}{} & \multicolumn{4}{c|}{} \\
%...

enter image description here

In order to control the spacing more precisely, you can use the e-TeX \dimexpr in the following way:

%...
\begin{tabular}{|l|c||*{4}{c|}|*{4}{c|}} \hline
& & \multicolumn{4}{c||}{} & \multicolumn{4}{c|}{} \\[\dimexpr-\normalbaselineskip+\jot]
%...

This will "back skip" \normalbaselineskip and then "forward skip" \jot, leaving you with a 3pt (the dimension of \jot) between the rules.

Related Question