\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}
我diagbox
与 一起使用multirow
,但对角线无法真正接触到框的西北角和东南角。如何解决这个问题?
答案1
由于您在表格中使用了arraystretch
,1.5
因此您必须将 的高度从 改为。diagbox
但是,您会注意到对角线水平线之间以及垂直线和水平线之间的间隙很小。这是由于使用了与垂直线不兼容的包中的水平线。3\line
4.5\line
booktabs
booktabs
因此,在第二个示例中,我将中的线条替换为 ,\hlines
这样间隙就消失了。我还删除了 ,\resizebox
因为这会导致整个文档中的字体大小不一致。
就我个人而言,我会重新设计您的表格,如第三个示例所示,没有垂直线和对角线:
\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}
答案2
变体:
\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
\begin{tabular}{@{}l*{8}{c}@{}}
\toprule
\multicolumn{1}{r}{Met\rlap{hods:}}& \multicolumn{3}{c}{plain} & \multicolumn{5}{c}{advanced}\\
\cmidrule(lr){2-4} \cmidrule(l){5-9}
\makecell{\multirow{2.3}{*}{Dataset}} & \multirow{2.3}{*}{\nv} & \multirow{2.3}{*}{\nvlca} & \multirow{2.3}{*}{\ext} & \multirow{2.3}{*}{\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}
答案3
下面展示了如何使用 构建此类表格nicematrix
。
但是,正如其他答案所说,我建议采用本着 精神的设计booktabs
。
\documentclass{article}
\usepackage{xcolor}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{nicematrix}
\begin{document}
\begin{table*}
\centering
\renewcommand{\arraystretch}{1.5}
\begin{NiceTabular}{@{}>{\ttfamily}l|rrr|rrrrr@{}}
\toprule
\Block{3-1}
{
\diagbox
{\rule[-2mm]{0pt}{2mm}Dataset}
{\rule{0pt}{4mm}Method }
}
& \Block{1-3}{plain} &&& \Block{1-5}{advanced} \\
\RowStyle{\ttfamily}
& \Block{2-1}{nv} & \Block{2-1}{nv.lca} & \Block{2-1}{ext} & \Block{2-1}{nv.succ} & \Block{1-2}{wt.hpd} && \Block{1-2}{ext} \\
\RowStyle{\itshape} & & & & & c & p & c & p\\
\midrule
eu.mst.osm & x & y & a & b & c & d & e & f\\
eu.emst.dem & x & y & a & b & c & d & e & f\\
\bottomrule
\end{NiceTabular}
\caption{}
\end{table*}
\end{document}