# table rescaling and subcaption package

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}


-
Mico's answer gives a good solution but for tabularx you need to specify which columns may stretch, using X column type. Also 1\textwidth is the same as \textwidth –  David Carlisle Jun 6 at 12:22

You could (i) use the tabular* instead of the tabular (or tabularx) environment, (ii) set the width of the tabular* 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 of 2\tabcolsep between columns in a tabular... 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 of 6pt to 1pt and let LaTeX then insert \fill for extra separation, and (ii) change the font size to \small (which is 1pt less than the default font size).

\documentclass{article}
\usepackage{siunitx,booktabs,subcaption}
\setlength\tabcolsep{1pt}  % LaTeX default is 6pt
\sisetup{detect-weight=true,
detect-inline-weight=math,
table-format=1.2(2)}
\begin{document}
\begin{table}
\small % reduce font size by 1pt
\begin{subtable}{0.48\textwidth}
\begin{tabular*}{\linewidth}{@{}l
@{\extracolsep{\fill}} SS
S[table-format=2.2(2)]
S[table-format=2.2(2)]@{}}
\toprule
\phantom{Var.} &
\multicolumn{4}{c}{Error Quantiles}\\
\cmidrule{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)\\[1ex]
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)\\[1ex]
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}{0.48\textwidth}
\begin{tabular*}{\linewidth}{@{}l
@{\extracolsep{\fill}} SS
S[table-format=2.2(2)]
S[table-format=2.2(2)]@{}}
\toprule
\phantom{Var.}
&  \multicolumn{4}{c}{Error Quantiles}\\
\cmidrule{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)\\[1ex]
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)\\[1ex]
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}
\end{document}


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):

-
\centering can still be used in order to ensure a zero parindent. –  egreg Jun 6 at 12:17
@egreg - Isn't \parindent already set to 0 inside a table environment? –  Mico Jun 6 at 12:18
Yes, it is; but other classes might not follow the standard ones in this respect. –  egreg Jun 6 at 12:21
Thanks, this looks like a much cleaner solution. However, in actual fact my tables are larger, although with the same number of columns. I have amended the question accordingly. Now I get overfull hbox errors, e.g. the table isn't scaling down to 0.48\textwidth... –  Patrick Jun 6 at 14:26
@user1753262 - Could you give an indication of the actual value of \textwidth -- the width of the page minus the margins -- of your document? –  Mico Jun 6 at 17:54

tabularx can still be used. For me it is straight forward than tabular*.

\documentclass{article}
\usepackage{siunitx,booktabs,subcaption,tabularx}
\usepackage[margin=1in]{geometry} % choose margins here
\begin{document}
\begin{table}
\sisetup{detect-weight=true,detect-inline-weight=math}
\begin{subtable}[b]{0.48\textwidth}
\begin{tabularx}{\linewidth}{@{}X%
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
Stuff & {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{tabularx}%
\caption{First subtable}
\end{subtable}%
\hspace*{\fill}%  % fill up space between the two subtables
\begin{subtable}[b]{0.48\textwidth}
\begin{tabularx}{\linewidth}{@{}X%
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
Stuff & {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{tabularx}%
\caption{Second subtable}
\end{subtable}
\caption{Overall table caption}
\end{table}
\end{document}

-
That puts all the variability in the first column, which is OK here as the line is fairly full but if the line was wide compared to the table data the first column would look a long way off. –  David Carlisle Jun 7 at 12:28
@DavidCarlisle you are right. I just wanted to show that in this particular example, tabularx can work. –  cacamailg Jun 7 at 12:40