4

Is there a definitive way to add table notes to an xtable that will wrap if the tablenote is longer than the width of the table? I have referenced this question here which proposes splitting long table notes into multiple lines and adding it to add.to.row. argument. Is there a way to avoid doing that and have it wrap automatically?

If I was using Latex only, I would use \usepackage{threeparttable}[flushleft] and use the code below. However, I do not believe you can add the \end{tabular} line with the add.to.row arguement.

Thanks in advance!

\documentclass{article}
\usepackage{threeparttable}[flushleft]
\usepackage{booktabs}

\begin{document}

      \begin{table}
        \centering
        \caption{Here is a caption}
        \begin{threeparttable}
          \begin{tabular}{lll}
          \toprule
          Entry A\tnote{1}   &   Entry B   &  Entry C   \\
          Entry D\tnote{2}   &   Entry E   &  Entry F   \\
          Entry G   &   Entry H   &  Entry I   \\
          \bottomrule
          \end{tabular}%
          \begin{tablenotes}
            \item[1] Here is my first note.
            \item[2] And here is my second note.
          \end{tablenotes}
        \end{threeparttable}
        \label{tab:table}%
      \end{table}%

\end{document}
Prevost
  • 677
  • 5
  • 20
  • I tend to use `\parbox` to force wrapping, but have forgotten the implementation details with `xtable`. – lmo Oct 26 '17 at 13:28
  • 2
    [this](https://stackoverflow.com/questions/26790530/xtable-adding-a-title-on-top-and-a-caption-under-the-table) gives another way - but again not automagic. Perhaps you may find it easier to just use the contents of the xtable (`only.contents=TRUE` in `print.xtable`), with additional use your standard latex code. Wouldnt be too difficult to wrap this in a function. – user20650 Oct 26 '17 at 18:09
  • @user20650 I will give that a try. I was not familiar with `only.contents` in xtable but we should be able to add the stuff to the top and bottom relatively easily! – Prevost Oct 26 '17 at 19:53
  • An example of the advice from @user20650 is provided here https://stackoverflow.com/questions/19904105/r-sweave-latex-place-comment-in-table-xtable/47004810#47004810 – Cedric Nov 08 '17 at 21:32

0 Answers0