I am placing tables side-by-side using the subcaption
package in the following way:
\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{subcaption}
\usepackage{tabularx}
\begin{document}
\begin{table}
\centering
\begin{subtable}[b]{0.48\textwidth}
\large
\resizebox{\textwidth}{!}
{%
\sisetup{detect-weight=true,detect-inline-weight=math}
\begin{tabular}{rS[table-format=1.2(2)]S[table-format=1.2(2)]S[table-format=2.2(2)]S[table-format=2.2(2)]}
\toprule
& {25\%} & {50\%} & {75\%} & {95\%}\\
\midrule
A & 0.09(83) & 0.26(83) & 0.38(83) & 0.96 \\
B & 0.10(1) & 0.16(1) & 0.22(2) & 0.41(8)\\
C & 0.08(1) & 0.12(1) & 0.19(3) & 0.52(23)\\
\bottomrule
\end{tabular}%
}
\caption{}
\end{subtable}%
\hspace{0.02\textwidth}%
\begin{subtable}[b]{0.48\textwidth}
\large
\resizebox{\textwidth}{!}
{%
\sisetup{detect-weight=true,detect-inline-weight=math}
\begin{tabular}{rS[table-format=1.2(2)]S[table-format=1.2(2)]S[table-format=2.2(2)]S[table-format=2.2(2)]}
\toprule
& {25\%} & {50\%} & {75\%} & {95\%}\\
\midrule
A & 0.09(83) & 0.26(83) & 0.38(83) & 0.96 \\
B & 0.10(1) & 0.16(1) & 0.22(2) & 0.41(8)\\
C & 0.08(1) & 0.12(1) & 0.19(3) & 0.52(23)\\
\bottomrule
\end{tabular}%
}%
\caption{}
\end{subtable}
\end{table}
\end{document}
In a related post, one of the comments was that using \resizebox{1\textwidth}{!}
was bad style, since it leads to inconsistent font sizes. The suggestion was to use the tabularx
package instead. Thus I left out the resizebox
command and replaced the calls
to \begin{tabular}{...}
with \begin{tabularx}{\textwidth}{...}
.
However, now the tables are no longer rescaled to match the 0.48\textwidth
of the subtable. What am I missing? It's strange, since using \textwidth
in the resizebox
command correctly picks up on the size of the subtable.
EDIT: I should have noted that in actual fact my table is bigger, but with the same number of columns. Incorporating mico's answer, I get overfull hbox errors.
The problem is I can't make the page much wider due to the need for a large inner margin. This is where the resizebox command came in handy, although it isn't the right way to go. Here is an edited example:
\documentclass{article}
\usepackage{siunitx,booktabs,subcaption}
%\usepackage[margin=1in]{geometry} % choose margins here
\begin{document}
\sisetup{detect-weight=true,detect-inline-weight=math}
\begin{table}
\centering
\begin{subtable}[b]{0.48\textwidth}
\begin{tabular*}{\linewidth}{@{}l@{\extracolsep{\fill}}
S[table-format=1.2(2)]
S[table-format=1.2(2)]
S[table-format=2.2(2)]
S[table-format=2.2(2)]@{}}
\toprule
& \multicolumn{4}{c}{Error Quantiles}\\
\cmidrule(lr){2-5}
& {25\%} & {50\%} & {75\%} & {95\%}\\
\midrule
A & 0.17(1) & 0.25(3) & 0.33(2) & 0.43(2)\\
B & 0.09(1) & 0.12(1) & 0.17(2) & 0.26(5)\\
C & 0.07(1) & 0.09(1) & 0.11(1) & 0.16(1)\\
\\
A & 0.17(83) & 0.26(83) & 0.38(83) & 0.96 \\ % 1e7
B & 0.10(1) & 0.16(1) & 0.22(2) & 0.41(8)\\
C & 0.08(1) & 0.12(1) & 0.19(3) & 0.52(23)\\
\\
A & 0.37(6) & 0.73(15) & 1.66(63) & {201}\\ % 1e5
B & 0.07(1) & 0.09(1) & 0.15(2) & 15.50(33)\\
C & 0.06(0) & 0.09(1) & 0.12(1) & 0.20(2)\\
\bottomrule
\end{tabular*}%
\caption{}
\end{subtable}%
\hspace*{\fill}%
\begin{subtable}[b]{0.48\textwidth}
\begin{tabular*}{\linewidth}{@{}l@{\extracolsep{\fill}}
S[table-format=1.2(2)]
S[table-format=1.2(2)]
S[table-format=2.2(2)]
S[table-format=2.2(2)]@{}}
\toprule
& \multicolumn{4}{c}{Error Quantiles}\\
\cmidrule(lr){2-5}
& {25\%} & {50\%} & {75\%} & {95\%}\\
\midrule
A & 0.17(1) & 0.25(3) & 0.33(2) & 0.43(2)\\
B & 0.09(1) & 0.12(1) & 0.17(2) & 0.26(5)\\
C & 0.07(1) & 0.09(1) & 0.11(1) & 0.16(1)\\
\\
A & 0.17(83) & 0.26(83) & 0.38(83) & 0.96 \\ % 1e7
B & 0.10(1) & 0.16(1) & 0.22(2) & 0.41(8)\\
C & 0.08(1) & 0.12(1) & 0.19(3) & 0.52(23)\\
\\
A & 0.37(6) & 0.73(15) & 1.66(63) & {201}\\ % 1e5
B & 0.07(1) & 0.09(1) & 0.15(2) & 15.50(33)\\
C & 0.06(0) & 0.09(1) & 0.12(1) & 0.20(2)\\
\bottomrule
\end{tabular*}%
\caption{}
\end{subtable}
\end{table}
Best Answer
You could (i) use the
tabular*
instead of thetabular
(ortabularx
) environment, (ii) set the width of thetabular*
to\linewidth
, and (iii) use the (admittedly complicated-looking) expression@{\extracolsep{\fill}}
to make LaTeX expand the intercolumn white space so that the contents of the table take up the full available width. (Unless instructed to do something else, LaTeX inserts intercolumn whitespace in the amount of2\tabcolsep
between columns in atabular...
environment.)Separately, I'd also get rid of the
\large
font size directive, use@{}
to get rid of the extra whitespace at the left and right margins of the tables, not use\centering
and instead use\hspace*{\fill}
to separate the two subtables, and make a few other changes here and there to streamline the setup and look of the tables.Addendum, posted after receiving information that the OP uses a fairly narrow text block: It's still possible to use the
tabular*
environment, but with two modifications relative to the code I posted originally (now deleted): (i) reduce the value of the\tabcolsep
parameter from the default value of6pt
to1pt
and let LaTeX then insert\fill
for extra separation, and (ii) change the font size to\small
(which is1pt
less than the default font size).Second Addendum: In case you feel that this setup (with font size
\small
, 10% smaller than the "normal" font size) doesn't provide enough whitespace between the columns, you could use\footnotesize
(20% smaller than the "normal" font size):