threeparttablex
can be used to add table notes to tabu
tabulars*. If the tabular spans \textwidth, the output is as expected. It seems however that the tablenotes environment does not adjust its width if the tabular is narrow, although of course this would be desirable.
1) Is there any option/command which is intended to automatically adjust the tablenotes environment's width?
2) If not, is there a workaround?
@ 2) According to this answer, threeparttablex
does know the tabular's width. Moreover, given that for the threeparttable
package, which threeparttablex
supposedly builds upon, the package documentation states "you can redefine the whole tablenotes environment", it seems that it should be possible to find a workaround.
\documentclass{article}
\usepackage{booktabs}
\usepackage{tabu}
\usepackage{threeparttablex}
\begin{document}
\centering
\begin{ThreePartTable}
\begin{tabu} to .4\textwidth {XX}
a & b \\\toprule
0 & 1 \\\bottomrule
\end{tabu}
\begin{tablenotes}
\footnotesize
\item[*] This is a long table note text, long enough to exceed the table's width.
\end{tablenotes}
\end{ThreePartTable}
\end{document}
*threeparttablex
is designed to extend threeparttable
to longtable
. Even though the manual does not mention it, threeparttablex
works with tabu
, which threeparttable
does not. Replacing threeparttablex
's ThreePartTable environment in the above code with a threeparttable environment gives an "Extra }, or forgotten \endgroup." error.
Best Answer
I don't know how to do it with
threeparttablex
, but it seems that the oldthreeparttable
should be sufficient: the former is forlongtable
and you don't seem to be usinglongtabu
(I'm afraid that one should rewritethreeparttablex
for using thelongtabu
environment).If you don't have
xpatch
, then change the lineinto
and load
etoolbox
instead ofxpatch
.How does the patch work? There is, in
threeparttable.sty
a macro called\TPT@hookin
which wants as argument the name of the table making environment. Thethreeparttable
environment executes\TPT@hookin{tabular}
,\TPT@hookin{tabular*}
and\TPT@hookin{tabularx}
, so we simply want to add\TPT@hookin{tabu}
.There's a small complication in the fact that Donald Arsenau changes the category code of
*
to 11 when defining\threeparttable
. The patching macros provided byetoolbox
,xpatch
or evenregexpatch
all disassemble the command to patch and rebuild it in order to see if there's something with category codes that would make the patched macro behave differently from what's expected, so we need to take care of that change: the*
is set to category code 11 and than its original category code is restored.