[Tex/LaTex] diagbox and multirow: adjust the diagonal

diagboxmultirowtables

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{graphicx,array,multirow,pict2e}
\definecolor{lightgray}{gray}{0.9}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{diagbox} %table split headers
\usepackage{rotating}
\usepackage{eqparbox}
\usepackage{makecell,caption}


\newcommand{\ext}[0]{{\texttt{ext}}}
\newcommand{\nv}[0]{{\texttt{nv}}}
\newcommand{\nvlca}[0]{{\texttt{nv.lca}}}
\newcommand{\nvsuc}[0]{{\texttt{nv.succ}}}
\newcommand{\wthpd}[0]{{\texttt{wt.hpd}}}

\begin{document}
\begin{table*}
\centering
\resizebox{\columnwidth}{!}{%
\ra{1.5}
%\rowcolors{1}{}{lightgray}
\begin{tabular}{@{}l|rrr|rrrrr@{}}
\toprule
    \multirow{3}{*}{\diagbox[trim=l,height=3\line]%
    {\\ \\Dataset}{Method\\ \\}} & \multicolumn{3}{c|}{plain} & \multicolumn{5}{c}{advanced}\\
                                                    & \multirow{2}{*}{\nv} & \multirow{2}{*}{\nvlca} & \multirow{2}{*}{\ext} & \multirow{2}{*}{\nvsuc} & \multicolumn{2}{c}{\wthpd} & \multicolumn{2}{c}{\ext}\\
                                                    & {}                  & {}                      & {}                   & {}                       & 
                                                    \multicolumn{1}{c}{\textit{c}} & \multicolumn{1}{c}{\textit{p}} & \multicolumn{1}{c}{\textit{c}} & \multicolumn{1}{c}{\textit{p}}\\
    \midrule
    {\texttt{eu.mst.osm}} & {x} & {y} & {a} & {b} & {c} & {d} & {e} & {f}\\
    {\texttt{eu.emst.dem}}& {x} & {y} & {a} & {b} & {c} & {d} & {e} & {f}\\
\bottomrule
\end{tabular}
}
\caption{}
\end{table*}
\end{document}

I use diagbox in conjunction with multirow, and cannot get the diagonal line to actually touch the north-west and south-east corners of the box.
How to fix this?

Best Answer

Since you use an arraystretch of 1.5 for your table, you will have to change the height of the diagbox from 3\line to 4.5\line. However, you will notice the small gap between the diagonal horizontal line as well as between the vertical and the horizontal lines. This is due to the usage of the horizontal lines from the booktabs package that are incompatible with vertical lines.

In the second example, I have therefore replaced the lines from booktabs by \hlines to the gaps disappear. I have also removed the \resizebox as this will lead to inconsistent font sizes throughout your document.

Personally, I would redesign your table, as shown in the third example, wihout vertical and diagonal lines:

enter image description here

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{graphicx,array,multirow,pict2e}
\definecolor{lightgray}{gray}{0.9}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{diagbox} %table split headers
\usepackage{rotating}
\usepackage{eqparbox}
\usepackage{makecell,caption}


\newcommand{\ext}[0]{{\texttt{ext}}}
\newcommand{\nv}[0]{{\texttt{nv}}}
\newcommand{\nvlca}[0]{{\texttt{nv.lca}}}
\newcommand{\nvsuc}[0]{{\texttt{nv.succ}}}
\newcommand{\wthpd}[0]{{\texttt{wt.hpd}}}

\begin{document}
\begin{table*}
\centering
\resizebox{\columnwidth}{!}{%
\ra{1.5}
%\rowcolors{1}{}{lightgray}
\begin{tabular}{@{}l|rrr|rrrrr@{}}
\toprule
    \multirow{3}{*}{\diagbox[trim=l,height=4.5\line]%
    {\\ \\Dataset}{Method\\ \\}} & \multicolumn{3}{c|}{plain} & \multicolumn{5}{c}{advanced}\\
                                                    & \multirow{2}{*}{\nv} & \multirow{2}{*}{\nvlca} & \multirow{2}{*}{\ext} & \multirow{2}{*}{\nvsuc} & \multicolumn{2}{c}{\wthpd} & \multicolumn{2}{c}{\ext}\\
                                                    & {}                  & {}                      & {}                   & {}                       & 
                                                    \multicolumn{1}{c}{\textit{c}} & \multicolumn{1}{c}{\textit{p}} & \multicolumn{1}{c}{\textit{c}} & \multicolumn{1}{c}{\textit{p}}\\
    \midrule
    {\texttt{eu.mst.osm}} & {x} & {y} & {a} & {b} & {c} & {d} & {e} & {f}\\
    {\texttt{eu.emst.dem}}& {x} & {y} & {a} & {b} & {c} & {d} & {e} & {f}\\
\bottomrule
\end{tabular}
}
\caption{}
\end{table*}

\begin{table*}
\centering
\ra{1.5}
%\rowcolors{1}{}{lightgray}
\begin{tabular}{@{}l|rrr|rrrrr@{}}
\hline
    \multirow{3}{*}{\diagbox[trim=l,height=4.5\line]%
    {\\ \\Dataset}{Method\\ \\}} & \multicolumn{3}{c|}{plain} & \multicolumn{5}{c}{advanced}\\
                                                    & \multirow{2}{*}{\nv} & \multirow{2}{*}{\nvlca} & \multirow{2}{*}{\ext} & \multirow{2}{*}{\nvsuc} & \multicolumn{2}{c}{\wthpd} & \multicolumn{2}{c}{\ext}\\
                                                    & {}                  & {}                      & {}                   & {}                       & 
                                                    \multicolumn{1}{c}{\textit{c}} & \multicolumn{1}{c}{\textit{p}} & \multicolumn{1}{c}{\textit{c}} & \multicolumn{1}{c}{\textit{p}}\\
    \hline
    {\texttt{eu.mst.osm}} & {x} & {y} & {a} & {b} & {c} & {d} & {e} & {f}\\
    {\texttt{eu.emst.dem}}& {x} & {y} & {a} & {b} & {c} & {d} & {e} & {f}\\
\hline
\end{tabular}
\caption{}
\end{table*}

\begin{table}
\centering
\begin{tabular}{@{}lcccccccc@{}}
\toprule
 Dataset & \multicolumn{8}{c}{Methods} \\ \cmidrule{2-9}
& \multicolumn{3}{c}{plain} & \multicolumn{5}{c}{advanced}\\ \cmidrule(r){2-4} \cmidrule{5-9}
                                                    & \nv & \nvlca & \ext & \nvsuc & \multicolumn{2}{c}{\wthpd} & \multicolumn{2}{c}{\ext}\\ \cmidrule(r){6-7} \cmidrule{8-9}
                                                    & {}                  & {}                      & {}                   & {}                       & 
                                                    \multicolumn{1}{c}{\textit{c}} & \textit{p} & \textit{c} & \textit{p}\\
    \midrule
    \texttt{eu.mst.osm} & x & y & a & b & c & d & e & f\\
    \texttt{eu.emst.dem}& x & y & a & b & c & d & e & f\\
\bottomrule
\end{tabular}
\caption{}
\end{table}
\end{document} 
Related Question