我有一张桌子,但是有两个问题:
边界线尚未完成
如果我添加标题,表格就会混乱
\usepackage{multirow}
\scalebox{0.7}{
%\caption{Result of all evaluation metrics in \cite{lim2023robust}}
%\label{table2.2}
\begin{tabularx}{\textwidth}{|l|l|lllll|}
\cline{1-7}
%\hline
\multirow{2}{*}{Dataset} & \multirow{2}{*}{Evaluation metric} & \multicolumn{5}{c}{Machine learning models} \\
\cline{3-7}
& & LR & NB & RF & XGBoost & SVM RBF \\
\cline{1-7}
\multirow{5}{*}{\begin{tabular}[c]{@{}l@{}}Training set\\cross-validation\end{tabular}} & Mean AUC & 0.992 & 0.990 & 0.994 & 0.994 & 0.992 \\
& Mean Sensitivity & 0.968 & 0.975 & 0.975 & 0.973 & 0.968 \\
& Mean Specificity & 0.963 & 0.956 & 0.962 & 0.963 & 0.965 \\
& Mean accuracy & 0.966 & 0.966 & 0.968 & 0.968 & 0.966 \\
& Mean average precision & 0.979 & 0.973 & 0.980 & 0.981 & 0.968 \\ \cline{1-7}
\multirow{6}{*}{\begin{tabular}[c]{@{}l@{}}Test 1 evaluation\end{tabular}} & AUC & 0.990 & 0.986 & 0.993 & 0.994 & 0.991 \\
& Sensitivity & 0.928 & 0.936 & 0.928 & 0.936 & 0.936 \\
& Specificity & 0.963 & 0.960 & 0.963 & 0.963 & 0.963 \\
& F1 score & 0.913 & 0.914 & 0.913 & 0.918 & 0.918 \\
& Accuracy & 0.945 & 0.948 & 0.945 & 0.949 & 0.949 \\
& Avg .Precision & 0.970 & 0.951 & 0.975 & 0.976 & 0.970 \\ \cline{1-7}
\multirow{6}{*}{\begin{tabular}[c]{@{}l@{}}Test 2 evaluation\end{tabular}} & AUC & 0.988 & 0.982 & 0.989 & 0.992 & 0.990 \\
& Sensitivity & 0.937 & 0.945 & 0.945 & 0.945 & 0.937 \\
& Specificity & 0.961 & 0.961 & 0.963 & 0.963 & 0.963 \\
& F1 Score & 0.915 & 0.920 & 0.923 & 0.923 & 0.919 \\
& Accuracy & 0.949 & 0.953 & 0.954 & 0.954 & 0.950 \\
& Avg .Precision & 0.964 & 0.960 & 0.968 & 0.972 & 0.965 \\ \cline{1-7}
\multirow{6}{*}{\begin{tabular}[c]{@{}l@{}}Test 3 evaluation\end{tabular}} & AUC & 0.987 & 0.972 & 0.987 & 0.991 & 0.986 \\
& Sensitivity & 0.913 & 0.921 & 0.921 & 0.937 & 0.921 \\
& Specificity & 0.966 & 0.958 & 0.966 & 0.966 & 0.966 \\
& F1 Score & 0.910 & 0.903 & 0.914 & 0.922 & 0.914 \\
& Accuracy & 0.940 & 0.940 & 0.944 & 0.952 & 0.944 \\
& Avg .Precision & 0.961 & 0.936 & 0.958 & 0.965 & 0.946 \\
\cline{1-7}
\end{tabularx}
}
我该如何解决这个问题?如何添加标题而不混淆表格?
谢谢
答案1
要修复缺少边框的问题,您需要更改
\multicolumn{5}{c}{Machine learning models}
到
\multicolumn{5}{c|}{Machine learning models}
要使用\caption
和\label
命令,您需要将这些命令与tabularx
环境一起嵌入到环境中table
。
但是,不要只应用这些简单的修复。相反,我想鼓励您精简和简化 tabularx 材料,以便它有机会适合文本块的宽度,从而不需要调用\scalebox
。删除所有垂直线并在表格中使用更少但间距适当的水平线也会受到读者的赞赏。
\documentclass{article} % or some other suitable document class
\usepackage{tabularx} % for 'tabularx' and 'X' column type
\usepackage{ragged2e} % for '\Centering' macro
\newcolumntype{C}{>{\Centering}X} % centered version of 'X' column type
\usepackage{booktabs} % for well-spaced horiz. rules (\toprule, etc)
\begin{document}
\begin{table}[ht]
\setlength{\tabcolsep}{3pt} % default: 6pt
\caption{Result of all evaluation metrics in \cite{lim2023robust}}
\label{tab:results}
\begin{tabularx}{\textwidth}{@{} l CCCCC @{}}
\toprule
Evaluation metric & \multicolumn{5}{c@{}}{Machine learning models} \\
\cmidrule(l){2-6}
& LR & NB & RF & XGBoost & SVM RBF \\
\midrule
Training set CV \\[0.5ex]
Mean AUC & 0.992 & 0.990 & 0.994 & 0.994 & 0.992 \\
Mean Sensitivity & 0.968 & 0.975 & 0.975 & 0.973 & 0.968 \\
Mean Specificity & 0.963 & 0.956 & 0.962 & 0.963 & 0.965 \\
Mean accuracy & 0.966 & 0.966 & 0.968 & 0.968 & 0.966 \\
Mean avg.\ prec. & 0.979 & 0.973 & 0.980 & 0.981 & 0.968 \\
\addlinespace
Test 1 evaluation \\[0.5ex]
AUC & 0.990 & 0.986 & 0.993 & 0.994 & 0.991 \\
Sensitivity & 0.928 & 0.936 & 0.928 & 0.936 & 0.936 \\
Specificity & 0.963 & 0.960 & 0.963 & 0.963 & 0.963 \\
F1 score & 0.913 & 0.914 & 0.913 & 0.918 & 0.918 \\
Accuracy & 0.945 & 0.948 & 0.945 & 0.949 & 0.949 \\
Avg.\ prec. & 0.970 & 0.951 & 0.975 & 0.976 & 0.970 \\
\addlinespace
Test 2 evaluation \\[0.5ex]
AUC & 0.988 & 0.982 & 0.989 & 0.992 & 0.990 \\
Sensitivity & 0.937 & 0.945 & 0.945 & 0.945 & 0.937 \\
Specificity & 0.961 & 0.961 & 0.963 & 0.963 & 0.963 \\
F1 Score & 0.915 & 0.920 & 0.923 & 0.923 & 0.919 \\
Accuracy & 0.949 & 0.953 & 0.954 & 0.954 & 0.950 \\
Avg.\ prec. & 0.964 & 0.960 & 0.968 & 0.972 & 0.965 \\
\addlinespace
Test 3 evaluation \\[0.5ex]
AUC & 0.987 & 0.972 & 0.987 & 0.991 & 0.986 \\
Sensitivity & 0.913 & 0.921 & 0.921 & 0.937 & 0.921 \\
Specificity & 0.966 & 0.958 & 0.966 & 0.966 & 0.966 \\
F1 Score & 0.910 & 0.903 & 0.914 & 0.922 & 0.914 \\
Accuracy & 0.940 & 0.940 & 0.944 & 0.952 & 0.944 \\
Avg.\ prec. & 0.961 & 0.936 & 0.958 & 0.965 & 0.946 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
答案2
tabularx
不错的 @mico 答案 (+1) 的一个小变化,其中使用了而不是package tabularray
。使用它,MWE (至少在我看来) 更简单、简洁和一致:
\documentclass{article}
\usepackage[skip=1ex,
font=small,
labelfont=bf]{caption}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\NewTableCommand\subtitle[1]{%
\SetCell[c=#1]{l, font=\bfseries\itshape,
cmd = \rule[-0.5ex]{0pt}{3.5ex}
}
}% end of NewTableCommand
\begin{document}
\begin{table}
\caption{Result of all evaluation metrics in \cite{lim2023robust}}
\label{tab:tab1}
\begin{tblr}{colspec = {@{} Q[l,rightsep+=4pt]
*{4}{X[c]}
X[1.2, c] @{}},
cell{1}{1} = {r=2}{},
cell{1}{2} = {c=5}{},
row{3-Z} = {rowsep=0.5pt}
}
\toprule
Evaluation metric & Machine learning models \\
\midrule
& LR & NB & RF & XGBoost & SVM RBF \\
\midrule
\subtitle{6} Training set CV \\
Mean AUC & 0.992 & 0.990 & 0.994 & 0.994 & 0.992 \\
Mean Sensitivity & 0.968 & 0.975 & 0.975 & 0.973 & 0.968 \\
Mean Specificity & 0.963 & 0.956 & 0.962 & 0.963 & 0.965 \\
Mean accuracy & 0.966 & 0.966 & 0.968 & 0.968 & 0.966 \\
Mean avg.\ prec. & 0.979 & 0.973 & 0.980 & 0.981 & 0.968 \\
\subtitle{6} Test 1 evaluation \\
AUC & 0.990 & 0.986 & 0.993 & 0.994 & 0.991 \\
Sensitivity & 0.928 & 0.936 & 0.928 & 0.936 & 0.936 \\
Specificity & 0.963 & 0.960 & 0.963 & 0.963 & 0.963 \\
F1 score & 0.913 & 0.914 & 0.913 & 0.918 & 0.918 \\
Accuracy & 0.945 & 0.948 & 0.945 & 0.949 & 0.949 \\
Avg.\ prec. & 0.970 & 0.951 & 0.975 & 0.976 & 0.970 \\
\subtitle{6} Test 2 evaluation \\
AUC & 0.988 & 0.982 & 0.989 & 0.992 & 0.990 \\
Sensitivity & 0.937 & 0.945 & 0.945 & 0.945 & 0.937 \\
Specificity & 0.961 & 0.961 & 0.963 & 0.963 & 0.963 \\
F1 Score & 0.915 & 0.920 & 0.923 & 0.923 & 0.919 \\
Accuracy & 0.949 & 0.953 & 0.954 & 0.954 & 0.950 \\
Avg.\ prec. & 0.964 & 0.960 & 0.968 & 0.972 & 0.965 \\
\subtitle{6} Test 3 evaluation \\
AUC & 0.987 & 0.972 & 0.987 & 0.991 & 0.986 \\
Sensitivity & 0.913 & 0.921 & 0.921 & 0.937 & 0.921 \\
Specificity & 0.966 & 0.958 & 0.966 & 0.966 & 0.966 \\
F1 Score & 0.910 & 0.903 & 0.914 & 0.922 & 0.914 \\
Accuracy & 0.940 & 0.940 & 0.944 & 0.952 & 0.944 \\
Avg.\ prec. & 0.961 & 0.936 & 0.958 & 0.965 & 0.946 \\
\bottomrule
\end{tblr}
\end{table}
\end{document}
编辑:
的风格subtitle
基于我的一个类似的风格回答,有人可能会觉得有点夸张。但是,风格可以轻松改变,例如正如@mico 在我们的对话中所建议的那样:
NewTableCommand\subtitle[1]{%
\SetCell[c=#1]{l, font=\scshape,
cmd = \rule[-0.5ex]{0pt}{3.5ex}
}
}% end of NewTableCommand
其呈现的效果更吸引人:
为了练习如何设计“字幕”,另一种稍微夸张的风格:
\newcounter{ST}
\setcounter{ST}{0}
\NewTableCommand\subtitle[1]{%
\stepcounter{ST}
\ifnum\theST=1 \else \midrule[dashed] \fi
\SetCell[c=#1]{l, font=\scshape,
cmd = \rule[-0.5ex]{0pt}{3.5ex}
}
}% end of NewTableCommand
这使:
当然,你可以根据自己的喜好来定义自己的风格。我最喜欢@Mico 的建议。