# threeparttablex table notes for tabu tabulars with less than \textwidth

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.

-

I don't know how to do it with threeparttablex, but it seems that the old threeparttable should be sufficient: the former is for longtable and you don't seem to be using longtabu (I'm afraid that one should rewrite threeparttablex for using the longtabu environment).

\documentclass{article}
\usepackage{booktabs}
\usepackage{tabu}
\usepackage{threeparttable}

\usepackage{xpatch}
\makeatletter
\chardef\TPT@@@asteriskcatcode=\catcode*
\catcode*=11
\xpatchcmd{\threeparttable}
{\TPT@hookin{tabular}}
{\TPT@hookin{tabular}\TPT@hookin{tabu}}
{}{}
\catcode`*=\TPT@@@asteriskcatcode
\makeatother

\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}

If you don't have xpatch, then change the line

\xpatchcmd{\threeparttable}

into

\expandafter\patchcmd\csname\string\threeparttable\endcsname