[
如何添加如下图所示的这些行,需要添加任何包吗?底部图像来自 mdp 日志;当我将相同的代码添加到项目报告表内容时,没有出现水平线。
\begin{table}[H]
\caption{Classification report of 20s model \label{tab-category-20}}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{tabularx}{\textwidth}{CCCC}
\toprule
\textbf{} & \textbf{precision} & \textbf{recall} & \textbf{f1-score}\\
\midrule
Category 1 & 1.00 & 1.00 & 1.00\\
Category 2 & 0.99 & 0.99 & 0.99\\
Category 3 & 0.98 & 1.00 & 0.99\\
Category 4 & 0.99 & 0.98 & 0.98\\
\bottomrule
\end{tabularx}
\end{table}
\unskip
答案1
将您的代码片段插入到工作article
文档中,在序言中加载所有需要的包,这样就可以正常工作:
\documentclass{article}
\usepackage{booktabs, tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}
\begin{table}[ht]
\caption{Classification report of 20s model}
\label{tab-category-20}
\begin{tabularx}{\textwidth}{CCCC}
\toprule
\textbf{} & \textbf{precision} & \textbf{recall} & \textbf{f1-score}\\
\midrule
Category 1 & 1.00 & 1.00 & 1.00 \\
Category 2 & 0.99 & 0.99 & 0.99 \\
Category 3 & 0.98 & 1.00 & 0.99 \\
Category 4 & 0.99 & 0.98 & 0.98 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
附录:tabularray
您可能会喜欢由包帮助(版本 2022B)编写的带有库booktabs
和siunitx
(加载同名包)的 同一张表:
\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
\begin{document}
\begin{table}[ht]
\centering
\caption{Classification report of 20s model}
\label{tab-category-20}
\begin{tblr}{colspec = {l SSS},
row{1} = {font=\bfseries, c, guard}
}
\toprule
& precision
& recall
& f1-score \\
\midrule
Category 1 & 1.00 & 1.00 & 1.00 \\
Category 2 & 0.99 & 0.99 & 0.99 \\
Category 3 & 0.98 & 1.00 & 0.99 \\
Category 4 & 0.99 & 0.98 & 0.98 \\
\bottomrule
\end{tblr}
\end{table}
\end{document}