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}
tabularx
you need to specify which columns may stretch, usingX
column type. Also1\textwidth
is the same as\textwidth