我创建了一个包含不同值的表格,我想为这两列添加一个“标题”。我想将文本“MP”和“Canny”稍微向左移动一点(我想位于文本“Acc”和“Coef Dice”之间)。我尝试删除其中一个符号“&”,但没有成功。
\begin{table}[ht]
\centering
\begin{adjustbox}{width=1\textwidth}
\small
\begin{tabular}{rrlrrrrrr}
& & && \rowfont{\large}MP& & & \rowfont{\large}Canny\\
\hline
& Img. &Imagine BSBD&Acc&Coef Dice & & Acc & Coef Dice\\
\hline
& 1 & 103070.jpg & 0.9017 &0.1789 & &0.8298 & 0.1767\\
& 2 & 104055.jpg & 0.9238 &0.2694 & &0.8530 &0.1864\\
& 3 & 106025.jpg & 0.9391 &0.2594 &&0.9487 &0.2145\\
& 4 & 108004.jpg & 0.8563 &0.3738 &&0.7539 &0.2291\\
& 5 & 108005.jpg & 0.8213 &0.1583 &&0.7878 &0.1477\\
& 6 & 108082.jpg & 0.8572 &0.0816 &&0.8296 &0.0885\\
& 7 & 109053.jpg &0.9166 & 0.1930 &&0.8273 &0.1682\\
&8 & 113044.jpg & 0.8967 &0.2802 &&0.7997 &0.1675\\
& 9 & 123057.jpg &0.9250 & 0.1407 &&0.8370 &0.14906\\
& 10 & 130026.jpg & 0.8718 &0.0879 &&0.8162 &0.0770\\
& 11 & 160068.jpg & 0.8691 &0.0968 &&0.8519 &0.1166\\
& 12 & 16077.jpg & 0.8822 &0.2614 &&0.7978 &0.1866\\
& 13 & 163014.jpg & 0.9182 &0.2778 &&0.8629 &0.2020\\
& 14 & 163085.jpg &0.8387 &0.1144 &&0.8113 &0.1778\\
& 15 & 167062.jpg &0.8928 &0.2264 &&0.9528 &0.2685\\
& 16 & 196027.jpg & 0.9358 &0.2596 &&0.9142 &0.2472\\
& 17 & 247003.jpg & 0.8020 &0.1571 &&0.7488 &0.2289\\
& 18 & 253027.jpg & 0.8421 &0.3308 &&0.8348 &0.2869\\
& 19 & 291000.jpg & 0.7741 &0.1585 &&0.6862 &0.1015\\
& 20 & 296007.jpg & 0.9638 &0.1927 &&0.8589 &0.1119\\
& 21 & 304034.jpg &0.7805 &0.2185 & & 0.7024 & 0.1522\\
& 22& 326038.jpg &0.8490 &0.3106 & &0.7688 &0.1652\\
& 23& 326085.jpg &0.8739 &0.1824 &&0.7880 &0.09560\\
& 24& 38092.jpg &0.8941 &0.4058 &&0.8103 &0.2324\\
& 25 & 41033.jpg &0.9461 &0.2834 &&0.8725 &0.1701\\
& 26& 42049.jpg &0.9506 &0.5688 &&0.9260 &0.3500\\
& 27& 43074.jpg &0.9004 &0.2247 &&0.8771 &0.1814\\
& 28& 69015.jpg &0.7865 &0.3290 && 0.7787 &0.2924\\
& 29& 69040.jpg &0.7371 &0.0876 & &0.7128 &0.1199\\
& 30 & 8023.jpg &0.9478 &0.0895 & &0.8611 &0.1016\\
\hline
\end{tabular}
\end{adjustbox}
\caption{.}
\end{table}
答案1
我建议采用基于数字数据的booktabs
解决方案。siunitx
\documentclass{article}
\usepackage{siunitx,booktabs,array}
\begin{document}
\begin{table}[htp]
\centering
% an ad hoc command for the second column header
\newcommand{\csplit}[1]{%
\multicolumn{1}{c}{\smash{\begin{tabular}[t]{@{}c@{}}#1\end{tabular}}}%
}
\begin{tabular}{
@{}
c
>{\ttfamily}r
*{3}{S[table-format=1.4]}
S[table-format=1.5,group-digits=false]
@{}
}
\toprule
Img. & \csplit{Imagine \\ BSBD} & \multicolumn{2}{c}{MP} & \multicolumn{2}{c}{Canny} \\
\cmidrule(lr){3-4} \cmidrule(l){5-6}
& & {Acc} & {Coef Dice} & {Acc} & {Coef Dice} \\
\midrule
1 & 103070.jpg & 0.9017 & 0.1789 & 0.8298 & 0.1767\\
2 & 104055.jpg & 0.9238 & 0.2694 & 0.8530 & 0.1864\\
3 & 106025.jpg & 0.9391 & 0.2594 & 0.9487 & 0.2145\\
4 & 108004.jpg & 0.8563 & 0.3738 & 0.7539 & 0.2291\\
5 & 108005.jpg & 0.8213 & 0.1583 & 0.7878 & 0.1477\\
6 & 108082.jpg & 0.8572 & 0.0816 & 0.8296 & 0.0885\\
7 & 109053.jpg & 0.9166 & 0.1930 & 0.8273 & 0.1682\\
8 & 113044.jpg & 0.8967 & 0.2802 & 0.7997 & 0.1675\\
9 & 123057.jpg & 0.9250 & 0.1407 & 0.8370 & 0.14906\\
10 & 130026.jpg & 0.8718 & 0.0879 & 0.8162 & 0.0770\\
11 & 160068.jpg & 0.8691 & 0.0968 & 0.8519 & 0.1166\\
12 & 16077.jpg & 0.8822 & 0.2614 & 0.7978 & 0.1866\\
13 & 163014.jpg & 0.9182 & 0.2778 & 0.8629 & 0.2020\\
14 & 163085.jpg & 0.8387 & 0.1144 & 0.8113 & 0.1778\\
15 & 167062.jpg & 0.8928 & 0.2264 & 0.9528 & 0.2685\\
16 & 196027.jpg & 0.9358 & 0.2596 & 0.9142 & 0.2472\\
17 & 247003.jpg & 0.8020 & 0.1571 & 0.7488 & 0.2289\\
18 & 253027.jpg & 0.8421 & 0.3308 & 0.8348 & 0.2869\\
19 & 291000.jpg & 0.7741 & 0.1585 & 0.6862 & 0.1015\\
20 & 296007.jpg & 0.9638 & 0.1927 & 0.8589 & 0.1119\\
21 & 304034.jpg & 0.7805 & 0.2185 & 0.7024 & 0.1522\\
22 & 326038.jpg & 0.8490 & 0.3106 & 0.7688 & 0.1652\\
23 & 326085.jpg & 0.8739 & 0.1824 & 0.7880 & 0.09560\\
24 & 38092.jpg & 0.8941 & 0.4058 & 0.8103 & 0.2324\\
25 & 41033.jpg & 0.9461 & 0.2834 & 0.8725 & 0.1701\\
26 & 42049.jpg & 0.9506 & 0.5688 & 0.9260 & 0.3500\\
27 & 43074.jpg & 0.9004 & 0.2247 & 0.8771 & 0.1814\\
28 & 69015.jpg & 0.7865 & 0.3290 & 0.7787 & 0.2924\\
29 & 69040.jpg & 0.7371 & 0.0876 & 0.7128 & 0.1199\\
30 & 8023.jpg & 0.9478 & 0.0895 & 0.8611 & 0.1016\\
\bottomrule
\end{tabular}
\caption{This is the caption}
\end{table}
\end{document}
如果您确实想将表格放大到文本宽度(我会避免这种情况),您可以使用tabular*
而不是缩放。
\documentclass{article}
\usepackage{siunitx,booktabs,array}
\begin{document}
\begin{table}[htp]
\centering
% an ad hoc command for the second column header
\newcommand{\csplit}[1]{%
\multicolumn{1}{c}{\smash{\begin{tabular}[t]{@{}c@{}}#1\end{tabular}}}%
}
\begin{tabular*}{\textwidth}{
@{\extracolsep{\fill}}
c
>{\ttfamily}r
*{3}{S[table-format=1.4]}
S[table-format=1.5,group-digits=false]
@{}
}
\toprule
Img. & \csplit{Imagine \\ BSBD} & \multicolumn{2}{c}{MP} & \multicolumn{2}{c}{Canny} \\
\cmidrule(lr){3-4} \cmidrule(l){5-6}
& & {Acc} & {Coef Dice} & {Acc} & {Coef Dice} \\
\midrule
1 & 103070.jpg & 0.9017 & 0.1789 & 0.8298 & 0.1767\\
2 & 104055.jpg & 0.9238 & 0.2694 & 0.8530 & 0.1864\\
3 & 106025.jpg & 0.9391 & 0.2594 & 0.9487 & 0.2145\\
4 & 108004.jpg & 0.8563 & 0.3738 & 0.7539 & 0.2291\\
5 & 108005.jpg & 0.8213 & 0.1583 & 0.7878 & 0.1477\\
6 & 108082.jpg & 0.8572 & 0.0816 & 0.8296 & 0.0885\\
7 & 109053.jpg & 0.9166 & 0.1930 & 0.8273 & 0.1682\\
8 & 113044.jpg & 0.8967 & 0.2802 & 0.7997 & 0.1675\\
9 & 123057.jpg & 0.9250 & 0.1407 & 0.8370 & 0.14906\\
10 & 130026.jpg & 0.8718 & 0.0879 & 0.8162 & 0.0770\\
11 & 160068.jpg & 0.8691 & 0.0968 & 0.8519 & 0.1166\\
12 & 16077.jpg & 0.8822 & 0.2614 & 0.7978 & 0.1866\\
13 & 163014.jpg & 0.9182 & 0.2778 & 0.8629 & 0.2020\\
14 & 163085.jpg & 0.8387 & 0.1144 & 0.8113 & 0.1778\\
15 & 167062.jpg & 0.8928 & 0.2264 & 0.9528 & 0.2685\\
16 & 196027.jpg & 0.9358 & 0.2596 & 0.9142 & 0.2472\\
17 & 247003.jpg & 0.8020 & 0.1571 & 0.7488 & 0.2289\\
18 & 253027.jpg & 0.8421 & 0.3308 & 0.8348 & 0.2869\\
19 & 291000.jpg & 0.7741 & 0.1585 & 0.6862 & 0.1015\\
20 & 296007.jpg & 0.9638 & 0.1927 & 0.8589 & 0.1119\\
21 & 304034.jpg & 0.7805 & 0.2185 & 0.7024 & 0.1522\\
22 & 326038.jpg & 0.8490 & 0.3106 & 0.7688 & 0.1652\\
23 & 326085.jpg & 0.8739 & 0.1824 & 0.7880 & 0.09560\\
24 & 38092.jpg & 0.8941 & 0.4058 & 0.8103 & 0.2324\\
25 & 41033.jpg & 0.9461 & 0.2834 & 0.8725 & 0.1701\\
26 & 42049.jpg & 0.9506 & 0.5688 & 0.9260 & 0.3500\\
27 & 43074.jpg & 0.9004 & 0.2247 & 0.8771 & 0.1814\\
28 & 69015.jpg & 0.7865 & 0.3290 & 0.7787 & 0.2924\\
29 & 69040.jpg & 0.7371 & 0.0876 & 0.7128 & 0.1199\\
30 & 8023.jpg & 0.9478 & 0.0895 & 0.8611 & 0.1016\\
\bottomrule
\end{tabular*}
\caption{This is the caption}
\end{table}
\end{document}
答案2
\documentclass[10pt,a4paper]{article}
\usepackage{siunitx}
\begin{document}
\begin{table}[ht]
\centering
% \begin{adjustbox}{width=1\textwidth}
\small
\begin{tabular}{crSSSS}
&& \multicolumn{2}{c}{\large MP}&\multicolumn{2}{c}{\large Canny}\\
\hline
Img. &Imagine BSBD& \multicolumn{1}{c}{Acc}&\multicolumn{1}{c}{Coef Dice} & \multicolumn{1}{c}{Acc} & \multicolumn{1}{c}{Coef Dice}\\
\hline
1 & 103070.jpg & 0.9017 &0.1789 &0.8298 & 0.1767\\
2 & 104055.jpg & 0.9238 &0.2694 &0.8530 &0.1864\\
3 & 106025.jpg & 0.9391 &0.2594 &0.9487 &0.2145\\
4 & 108004.jpg & 0.8563 &0.3738 &0.7539 &0.2291\\
5 & 108005.jpg & 0.8213 &0.1583 &0.7878 &0.1477\\
6 & 108082.jpg & 0.8572 &0.0816 &0.8296 &0.0885\\
7 & 109053.jpg &0.9166 & 0.1930 &0.8273 &0.1682\\
8 & 113044.jpg & 0.8967 &0.2802 &0.7997 &0.1675\\
9 & 123057.jpg &0.9250 & 0.1407 &0.8370 &0.14906\\
10 & 130026.jpg & 0.8718 &0.0879 &0.8162 &0.0770\\
11 & 160068.jpg & 0.8691 &0.0968 &0.8519 &0.1166\\
12 & 16077.jpg & 0.8822 &0.2614 &0.7978 &0.1866\\
13 & 163014.jpg & 0.9182 &0.2778 &0.8629 &0.2020\\
14 & 163085.jpg &0.8387 &0.1144 &0.8113 &0.1778\\
15 & 167062.jpg &0.8928 &0.2264 &0.9528 &0.2685\\
16 & 196027.jpg & 0.9358 &0.2596 &0.9142 &0.2472\\
17 & 247003.jpg & 0.8020 &0.1571 &0.7488 &0.2289\\
18 & 253027.jpg & 0.8421 &0.3308 &0.8348 &0.2869\\
19 & 291000.jpg & 0.7741 &0.1585 &0.6862 &0.1015\\
20 & 296007.jpg & 0.9638 &0.1927 &0.8589 &0.1119\\
21 & 304034.jpg &0.7805 &0.2185 & 0.7024 & 0.1522\\
22& 326038.jpg &0.8490 &0.3106 &0.7688 &0.1652\\
23& 326085.jpg &0.8739 &0.1824 &0.7880 &0.09560\\
24& 38092.jpg &0.8941 &0.4058 &0.8103 &0.2324\\
25 & 41033.jpg &0.9461 &0.2834&0.8725 &0.1701\\
26& 42049.jpg &0.9506 &0.5688&0.9260 &0.3500\\
27& 43074.jpg &0.9004 &0.2247 &0.8771 &0.1814\\
28& 69015.jpg &0.7865 &0.3290 & 0.7787 &0.2924\\
29& 69040.jpg &0.7371 &0.0876 &0.7128 &0.1199\\
30 & 8023.jpg &0.9478 &0.0895 &0.8611 &0.1016\\
\hline
\end{tabular}
% \end{adjustbox}
\caption{.}
\end{table}
\end{document}