如何在简单的表格中为一个单元格绘制边框?
\documentclass{article}
\usepackage{placeins}
\usepackage{booktabs ,float}
\begin{document}
\begin{table}[htbp]
\centering
\caption{Test Set }
\begin{tabular}{cccc}
\hline\hline
\multicolumn{2}{c}{\textbf{Train}}& \multicolumn{2}{c}{\textbf{Test}}\\
\cmidrule(r){1-2} \cmidrule(r){3-4}
\textbf{A} & \textbf{\# D} & \textbf{\# E} & \textbf{\# E} \\
\hline
B & 9.6 & 62.8& 62.8 \\
C & 12.0 & 78.9 & 62.8 \\
C & 12.0 & 78.9 & 62.8 \\
\hline
\end{tabular}
\end{table}
\end{document}
答案1
\documentclass{article}
\usepackage{placeins}
\usepackage{booktabs ,float}
\begin{document}
\begin{table}[htbp]
\centering
\renewcommand\arraystretch{1.2}
\caption{Test Set }
\begin{tabular}{cccc}
\hline\hline
\multicolumn{2}{c}{\textbf{Train}}& \multicolumn{2}{c}{\textbf{Test}}\\
\cmidrule(r){1-2} \cmidrule(r){3-4}
\textbf{A} & \textbf{\# D} & \textbf{\# E} & \textbf{\# E} \\
\hline
B & 9.6 & 62.8& 62.8 \\
C & 12.0 & \fbox{78.9} & 62.8 \\
C & 12.0 & 78.9 & 62.8 \\
\hline
\end{tabular}
\end{table}
\end{document}
我将对表格中的所有水平规则使用规则,booktabs
而不仅仅是一个......
答案2
你可以用 框住内容\fbox
。以确保垂直对齐不会改变
\documentclass{article}
\usepackage{booktabs,siunitx}
\newcommand{\boxnum}[2][table-format=2.1]{\smash{\fbox{\vphantom{#2}\tablenum[#1]{#2}}}}
\begin{document}
\begin{tabular}{ c *{3}{S[table-format=2.1]} }
\toprule
\multicolumn{2}{c}{\textbf{Train}} & \multicolumn{2}{c}{\textbf{Test}} \\
\cmidrule(r){1-2} \cmidrule(l){3-4}
{\textbf{A}} & {\textbf{\# D}} & {\textbf{\# E}} & {\textbf{\# E}} \\
\midrule
B & \multicolumn{1}{c}{\boxnum{9.6}} & 62.8 & 62.8 \\
C & 12.0 & 78.9 & \multicolumn{1}{c}{\boxnum{62.8}} \\
C & 12.0 & \multicolumn{1}{c}{\boxnum{78.9}} & 62.8 \\
\bottomrule
\end{tabular}
\end{document}
您还可以使用tabular
规则来构建元素:
\documentclass{article}
\usepackage{booktabs,siunitx}
\begin{document}
\begin{tabular}{ c *{3}{S[table-format=2.1]} }
\toprule
\multicolumn{2}{c}{\textbf{Train}} & \multicolumn{2}{c}{\textbf{Test}} \\
\cmidrule(r){1-2} \cmidrule(l){3-4}
{\textbf{A}} & {\textbf{\# D}} & {\textbf{\# E}} & {\textbf{\# E}} \\
\midrule
\cline{2-2}
B & \multicolumn{1}{|c|}{\tablenum[table-format=2.1]{9.6}} & 62.8 & 62.8 \\
\cline{2-2}
C & 12.0 & 78.9 & 62.8 \\
\cline{4-4}
C & 12.0 & 78.9 & \multicolumn{1}{|c|}{62.8} \\
\cline{4-4}
\bottomrule
\end{tabular}
\end{document}
有关的:突出显示矩阵中的元素