宽度相等的子表?

宽度相等的子表?

我正在尝试创建两个宽度相等(且水平对齐)的子表,但即使指定了相等的宽度,第二个表呈现(pdflatex)时也比第一个表小。更改第二个表的宽度会将其向右移动。有人能帮忙吗?

梅威瑟:

\documentclass{scrartcl}
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{booktabs}
\begin{document}

\begin{table}[H]
  \caption{\textbf{blabla.} bla.}\label{tblfoo}
  \centering

\begin{subtable}[t]{\textwidth}
  \centering
\caption{RefSeq-derived synthetic metagenome}
\begin{tabular}{@{}lrrrrr@{}}

  & Kraken & Kaiju & Centrifuge & MetaPhlAn 2 & MGX \\

\midrule

TP & 12,059,412 & 9,329,288 & 12,611,380 & 414,943 & 12,566,362 \\
FP & 18,748 & 185,899 & 53,092 & 7,171 & 20,698 \\
FN & 1,281,840 & 3,844,813 & 695,528 & 12,937,886 & 772,940 \\

\midrule

Sensitivity & 0.9039 & 0.7082 & \textbf{0.9477} & 0.0311 & 0.9421 \\
Precision & \textbf{0.9984} & 0.9805 & 0.9958 & 0.9830 & \textbf{0.9984} \\
Accuracy & 0.9027 & 0.6983 & \textbf{0.9440} & 0.0311 & 0.9406 \\
F1 score & 0.9488 & 0.8224 & \textbf{0.9712} & 0.0602 & 0.9694 \\

\bottomrule
\end{tabular}
\end{subtable}

\vspace*{5mm}
\centering

\begin{subtable}[t]{\textwidth}
  \centering
  \caption{GenBank-derived synthetic metagenome}

\begin{tabular}{@{}lrrrrr@{}}

  & Kraken & Kaiju & Centrifuge & MetaPhlAn 2 & MGX \\

\midrule

TP & 1,851,436 & 2,592,655 & 2,175,122 & 92,383 & 3,976,270 \\
FP & 398,899 & 1,230,445 & 864,989 & 10,378 & 734,389 \\
FN & 9,629,665 & 8,56,900 & 8,839,889 & 11,777,239 & 7,169,341 \\

\midrule

Sensitivity & 0.1613 & 0.2435 & 0.1975 & 0.0078 & \textbf{0.3568} \\
Precision & 0.8227 & 0.6782 & 0.7155 & \textbf{0.8990} & 0.8441 \\
Accuracy & 0.1558 & 0.2182 & 0.1831 & 0.0078 & \textbf{0.3347} \\
F1 score & 0.2697 & 0.3583 & 0.3095 & 0.0154 & \textbf{0.5015} \\

\bottomrule
  \end{tabular}
\end{subtable}

\end{table}

\end{document}

答案1

我建议您使用tabular*而不是tabular环境。具体来说,您可能希望将两个目标宽度都设置为\textwidth,如下例所示。

单独的建议:我将对表格数字使用“未扩展”粗体(而不是 TeX 默认的“扩展粗体”),以便非粗体和粗体表格数字具有相同的宽度。

在此处输入图片描述

\documentclass{scrartcl}
\usepackage{subcaption,booktabs}
\captionsetup[subtable]{size=normalsize, skip=0.5\baselineskip}
\newcommand{\ubold}[1]{\fontseries{b}\selectfont #1} % non-extended bold

\begin{document}

\begin{table}[ht!]
\setlength\tabcolsep{0pt} % let LaTeX determine intercolumn whitespace

\caption{\textbf{blabla.} bla.}\label{tblfoo}


\begin{subtable}[t]{\textwidth}
\caption{RefSeq-derived synthetic metagenome}

\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lrrrrr}
  & Kraken & Kaiju & Centrifuge & MetaPhlAn 2 & MGX \\
\midrule
TP & 12,059,412 & 9,329,288 & 12,611,380 & 414,943 & 12,566,362 \\
FP & 18,748 & 185,899 & 53,092 & 7,171 & 20,698 \\
FN & 1,281,840 & 3,844,813 & 695,528 & 12,937,886 & 772,940 \\
\midrule
Sensitivity & 0.9039 & 0.7082 & \ubold{0.9477} & 0.0311 & 0.9421 \\
Precision & \ubold{0.9984} & 0.9805 & 0.9958 & 0.9830 & \ubold{0.9984} \\
Accuracy & 0.9027 & 0.6983 & \ubold{0.9440} & 0.0311 & 0.9406 \\
F1 score & 0.9488 & 0.8224 & \ubold{0.9712} & 0.0602 & 0.9694 \\
\bottomrule
\end{tabular*}
\end{subtable}

\vspace*{5mm}

\begin{subtable}[t]{\textwidth}
\caption{GenBank-derived synthetic metagenome}

\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lrrrrr}
  & Kraken & Kaiju & Centrifuge & MetaPhlAn 2 & MGX \\
\midrule
TP & 1,851,436 & 2,592,655 & 2,175,122 & 92,383 & 3,976,270 \\
FP & 398,899 & 1,230,445 & 864,989 & 10,378 & 734,389 \\
FN & 9,629,665 & 8,56,900 & 8,839,889 & 11,777,239 & 7,169,341 \\
\midrule
Sensitivity & 0.1613 & 0.2435 & 0.1975 & 0.0078 & \ubold{0.3568} \\
Precision & 0.8227 & 0.6782 & 0.7155 & \ubold{0.8990} & 0.8441 \\
Accuracy & 0.1558 & 0.2182 & 0.1831 & 0.0078 & \ubold{0.3347} \\
F1 score & 0.2697 & 0.3583 & 0.3095 & 0.0154 & \ubold{0.5015} \\
\bottomrule
\end{tabular*}
\end{subtable}

\end{table}

\end{document}

答案2

不如以下优雅且自动化程度高Mico 的解决方案但您可以用来\widthof测量第一个表的列中最宽条目的宽度,并将此宽度用于第二个表的相应列(示例中的第 2 列和第 6 列):

\documentclass{scrartcl}
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{booktabs}

\usepackage{calc}
\usepackage{ragged2e}
\usepackage{array}
\begin{document}

\begin{table}[H]
  \caption{\textbf{blabla.} bla.}\label{tblfoo}
  \centering

\begin{subtable}[t]{\textwidth}
  \centering
\caption{RefSeq-derived synthetic metagenome}
\begin{tabular}{@{}lrrrrr@{}}

  & Kraken & Kaiju & Centrifuge & MetaPhlAn 2 & MGX \\

\midrule

TP & 12,059,412 & 9,329,288 & 12,611,380 & 414,943 & 12,566,362 \\
FP & 18,748 & 185,899 & 53,092 & 7,171 & 20,698 \\
FN & 1,281,840 & 3,844,813 & 695,528 & 12,937,886 & 772,940 \\

\midrule

Sensitivity & 0.9039 & 0.7082 & \textbf{0.9477} & 0.0311 & 0.9421 \\
Precision & \textbf{0.9984} & 0.9805 & 0.9958 & 0.9830 & \textbf{0.9984} \\
Accuracy & 0.9027 & 0.6983 & \textbf{0.9440} & 0.0311 & 0.9406 \\
F1 score & 0.9488 & 0.8224 & \textbf{0.9712} & 0.0602 & 0.9694 \\

\bottomrule
\end{tabular}
\end{subtable}

\vspace*{5mm}
\centering

\begin{subtable}[t]{\textwidth}
  \centering
  \caption{GenBank-derived synthetic metagenome}

\begin{tabular}{@{}l>{\RaggedLeft}p{\widthof{12,059,412}}rrr>{\RaggedLeft}p{\widthof{12,566,362}}@{}}

  & Kraken & Kaiju & Centrifuge & MetaPhlAn 2 & MGX \\

\midrule

TP & 1,851,436 & 2,592,655 & 2,175,122 & 92,383 & 3,976,270 \\
FP & 398,899 & 1,230,445 & 864,989 & 10,378 & 734,389 \\
FN & 9,629,665 & 8,56,900 & 8,839,889 & 11,777,239 & 7,169,341 \\

\midrule

Sensitivity & 0.1613 & 0.2435 & 0.1975 & 0.0078 & \textbf{0.3568} \\
Precision & 0.8227 & 0.6782 & 0.7155 & \textbf{0.8990} & 0.8441 \\
Accuracy & 0.1558 & 0.2182 & 0.1831 & 0.0078 & \textbf{0.3347} \\
F1 score & 0.2697 & 0.3583 & 0.3095 & 0.0154 & \textbf{0.5015} \\

\bottomrule
  \end{tabular}
\end{subtable}

\end{table}

\end{document}

在此处输入图片描述

相关内容