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}
![enter image description here](https://i.stack.imgur.com/qGXID.png)
If you don't have xpatch
, then change the line
\xpatchcmd{\threeparttable}
into
\expandafter\patchcmd\csname\string\threeparttable\endcsname
and load etoolbox
instead of xpatch
.
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. The threeparttable
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 by etoolbox
, xpatch
or even regexpatch
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.
Using \DeclareMarginSet
, you can declare a margin set allowing you to hang the object on both margins (there are predefined settings hangleft
, hangright
for each margin individually, but not for both of them simultaneouly); then, you can invoke this margin set together with an appropriate value for floatwidth
and rowfill=yes
. Something along these lines:
\documentclass{article}
\usepackage{graphicx}
\usepackage{floatrow}
\usepackage{lipsum}% just to generate text for the example
\DeclareMarginSet{hangboth}{\setfloatmargins*{\hskip-4cm}{\hskip-4cm}}
\begin{document}
\thisfloatsetup{floatwidth=\paperwidth,rowfill=yes,margins=hangboth}
\lipsum[4]
\begin{figure}[!ht]\CenterFloatBoxes
\begin{floatrow}
\ffigbox[\FBwidth]
{\includegraphics[width=10cm,height=4cm]{example-image-a}}
{\caption{figure caption}\label{figure}}
\ttabbox[\FBwidth]
{\begin{tabular}{lll}
column1a & column2a & column3a \\
column1b & column2b & column3b \\
column1c & column2c & column3c \\
column1d & column2d & column3d
\end{tabular}}
{\caption{table}}
\end{floatrow}
\end{figure}
\lipsum[4]
\end{document}
![enter image description here](https://i.stack.imgur.com/oTc93.png)
The option [!ht]
was only used for the example; I am bot recommending its use.
To have the caption for the table below it (although it's usual for table captions to appear above the table), you can use \floatbox
instead of \ttabbox
for the table and perhaps do some additional adjustment for the vertical alignment using heightadjust
and valign
:
\documentclass{article}
\usepackage{graphicx}
\usepackage[rawfloats]{floatrow}
\usepackage{lipsum}
\DeclareMarginSet{hangboth}{\setfloatmargins*{\hskip-4cm}{\hskip-4cm}}
\begin{document}
\thisfloatsetup{floatwidth=\paperwidth,rowfill=yes,margins=hangboth,heightadjust=all,valign=b}
\lipsum[4]
\begin{figure}[!ht]
\begin{floatrow}
\ffigbox[\FBwidth]
{\includegraphics[width=10cm,height=4cm]{example-image-a}}
{\caption{figure caption}\label{figure}}
\floatbox{table}[\FBwidth]
{\caption{table}}
{\begin{tabular}{lll}
column1a & column2a & column3a \\
column1b & column2b & column3b \\
column1c & column2c & column3c \\
column1d & column2d & column3d
\end{tabular}}
\end{floatrow}
\end{figure}
\lipsum[4]
\end{document}
![enter image description here](https://i.stack.imgur.com/zRn3Y.png)
Best Answer
I'm not sure why (
tabu
is somewhat surprising, usually), but specifying the innertabular
environments with@{}c@{}
instead ofc
seems to cure the problem.