This question consists of two related parts. I already solved the original problem but still don't understand where it came from or why the solution works.
I use the subcaption
package so I can place two subtables aside each other. Each subtable requires the intended width so I additionally use a savebox
to first create the table, then measure the width of the box in order to get the optimal subtable width and last but not least print the contents of the box.
\newsavebox{\tablebox}
\sbox{\tablebox}{
\begin{tabular}{ccc}
1st & 2nd & 3rd \\
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{tabular}
}
% create fitting subtable
\begin{subtable}{\wd\tablebox}
\usebox{\tablebox}
\caption{Subable}
\end{subtable}
However, pdflatex
started to give me the following warning
Underfull \hbox (badness 10000) in paragraph at lines 24--25
where 24 is the line the \usebox
is at.
This makes no sense because the subtable should have the exactly right width. Through trial and error I found out that the warning only occurs when all of the following three conditions hold:
- The given construct is used in the appendix (i.e. after
\appendix
). - The
cleveref
package is loaded. - There is no
%
at the end of the\usebox
line.
I do not understand why any of these has an influence at all...
My second question came up while trying to located the error. I replaced the second table with a \rule
of the same size, or at least that is what I tried to achieve. While the width ({\wd\tablebox}
) looks fine to me the height of the replacement ({\ht\tablebox}
) is wrong. It is much too narrow. Why?
Finally, a MWE that demonstrates all described effects. Please note that there is no warning for the actual table due to the %
but there is one for the replacement \rule
with the same width:
\documentclass[english]{scrreprt}
\usepackage{babel}
\usepackage{subcaption}
\usepackage{cleveref}
\begin{document}
\appendix
\newsavebox{\tablebox}
\begin{table}
% prepare table
\sbox{\tablebox}{
\begin{tabular}{ccc}
1st & 2nd & 3rd \\
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{tabular}
}
% create fitting subtable
\begin{subtable}{\wd\tablebox}
\usebox{\tablebox}% no warning for this table
\caption{Left Table}
\end{subtable}
%
\hspace{2ex}
%
% create fitting subtable
\begin{subtable}{\wd\tablebox}
\rule{\wd\tablebox}{\ht\tablebox}
\caption{Right Table}
\end{subtable}
\caption{Two Tables}
\end{table}
\end{document}
\sbox
: Add%
at the end of the first line (after the{
) and after\end{tabular}
.tabular
environment). Is this related to "horizontal" vs. "vertical" mode I keep reading about in various questions?\subcaptionbox
?