# Longtable captions do not wrap inside threeparttable environment

I'm using the threeparttable package to automatically wrap my captions to table width. However, I occasionally need to use longtable to split a table across multiple pages. When I do so, the caption no longer wraps to the width of the table, as you see in the two tables below. I tried including the caption package and setting the width with \captionsetup{width=4cm} to no avail but I'd rather have an automatic solution anyway as I have a number of long tables of varying width. Is there a fix or suitable alternative to threeparttable? (I do sometimes need the \tnote feature in threeparttable but I can probably work around that if necessary.)

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

\begin{document}
\begin{threeparttable}
\begin{tabular}{ll}
\caption{Caption for tabular does wrap inside threeparttable environment.}\\
\toprule
column1 & column2 \\
\midrule
info1 & info2\\
\bottomrule
\end{tabular}
\end{threeparttable}

\begin{threeparttable}
\begin{longtable}{ll}
\caption{Caption for longtable does not wrap inside threeparttable environment.}\\
\toprule
column1 & column2 \\
\midrule
info1 & info2\\
\bottomrule
\end{longtable}
\end{threeparttable}
\end{document}


• It doesn't make sense to use longtable inside threeparttable (or at least I can't think of anything sensible I could make it do there) If you want the caption to be as wide as the effective width of the table you can add up the saved column widths in the aux file. I'm sure I've done that in an answer here but I don't see it now, but google turned up a version from Heiko on comp.text.tex which looks about right. compgroups.net/comp.text.tex/longtable-tablewidth/1922986 – David Carlisle Jul 14 '14 at 20:33
• @DavidCarlisle - Heiko's solution seems to work. Thanks for the link. I'm not at all wed to threeparttable. It just solved the caption width problem for me based on an answer to another question on this site. For the sake of knowledge, why does it not make sense to use longtable inside of threeparttable? The manual states specifically that it facilitates tables with captions, and that such captions are given width equal to the table width. It works for tabular et al. but not for longtable. – Michael S Taylor Jul 14 '14 at 21:43
• a tabular is a box so you can measure its width and then set the minipage for table notes and captions to that width, which is what threeparttable does well. but boxes don't break over a page so longtable doesn't box the alignment so there's nothing threeparttable can do. – David Carlisle Jul 14 '14 at 22:13
• That makes sense to me now. If it's worth your effort, you can put the link to Heiko's solution in an answer for me to accept. – Michael S Taylor Jul 15 '14 at 0:35
• OK or I may see if Heiko's around and wants to pick up a point or two;-) – David Carlisle Jul 15 '14 at 8:18