7

I'm trying to create two subtables with equal width (and horizontally aligned), but the second table is getting rendered (pdflatex) smaller than the first one even with equal width specified. Changing the width of the second table shifted it to the right. Can someone help?

MWE:

\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}
2
  • Welcome to the users of TeX.SE. Generally to align numbers well within a table where there are semicolons it is good to use siunitx package.
    – Sebastiano
    Commented Jun 2, 2019 at 15:13
  • You have not ser any width for the tables (tabulars) environments, only for a containing box. For tables of fixed width, you have the tabularx and tabulary packages or the tabular* environment. You can also use only fixed width columns as p{2cm} in pain tabular if reach the witdh \textwidth is irrelevant.
    – Fran
    Commented Jun 2, 2019 at 15:21

2 Answers 2

5

I suggest you use tabular* instead of tabular environments. In particular, you may want to set both target widths to \textwidth, as is done in the following example.

A separate suggestion: I would use "unextended" bold (as opposed to the TeX default "extended bold") for tabular numbers, so that non-bold and bold tabular numerals have the same widths.

enter image description here

\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}
3

Less elegant and less automated than Mico's solution but you can use \widthof to measure the width of the widest entry in the column of the first table and use this width for the corresponding column in the second table (column 2 and 6 in your example):

\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}

enter image description here

3
  • 2
    Or, simply insert a \phantom{0} directive immediately before 1,851,436?
    – Mico
    Commented Jun 2, 2019 at 15:31
  • Perfect, I converted to tabular* and added \phantom{0} - that solved it. Thanks to all of you!
    – sjaenick
    Commented Jun 2, 2019 at 15:39
  • 1
    @Mico: Great idea that did not come to my mind.
    – leandriis
    Commented Jun 2, 2019 at 15:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .