This is a bit different than what you meant, but maybe you could just use xtable , which has the caption.width argument, for example:
print.xtable(xtable(mtcars[1:5, 1:3], caption="The main caption of the table"), caption.width="10cm", caption.placement="top")
The conclusion will not exactly match what you are going to do, but you can probably bend it for your own purposes if you prefer a more concise code; from ?print.xtable :
The signature will be placed in the "parbox" of the specified width, if caption.width is not NULL, but type = "latex". The default value is NULL.
Here's the conclusion:
% latex table generated in R 3.1.3 by xtable 1.7-4 package % Tue Jun 30 14:52:06 2015 \begin{table}[ht] \centering \parbox{5cm}{\caption{The main caption of the table}} \begin{tabular}{rrrr} \hline & mpg & cyl & disp \\ \hline Mazda RX4 & 21.00 & 6.00 & 160.00 \\ Mazda RX4 Wag & 21.00 & 6.00 & 160.00 \\ Datsun 710 & 22.80 & 4.00 & 108.00 \\ Hornet 4 Drive & 21.40 & 6.00 & 258.00 \\ Hornet Sportabout & 18.70 & 8.00 & 360.00 \\ \hline \end{tabular} \end{table}
You will also have to deal with other parameters (e.g. digits ) in order to get the exact formatting of the rest of the table according to what is specified in stargazer , depending on what exactly it formats what you had in mind.
source share