gt icon indicating copy to clipboard operation
gt copied to clipboard

Option to omit longtable environment in Latex

Open jonathandroth opened this issue 1 year ago • 8 comments

Thank you for the great package!

I think it would be great if the gtsave function had an option to omit the \begin{longtable} and \end{longtable} parts and only save the the text from \begin{tabular} to \end{tabular}. This would facilitate incorporating the output into Latex documents, and would be analogous to e.g. the contents_only option in xtable.

jonathandroth avatar Apr 17 '23 14:04 jonathandroth

I agree with this suggestion. Right now I am struggling to add captions and labels to LaTeX tables produced by the gt package and this would be an easy solution.

spittssj avatar Dec 08 '23 19:12 spittssj

@spittssj In case it's helpful as a work-around, I wrote some simple functions here to convert longtable to tabular in a text file. The same link also has a function to extract only the part between the \begin{tabular} and \end{tabular}. This post-processing worked pretty well for me, although it'd be great if it were eventually made internal to gt.

jonathandroth avatar Dec 12 '23 01:12 jonathandroth

@jonathandroth the link you provided doesn't work but the code you describes sounds useful. Can you check the link (or perhaps the security settings)? Thanks.

spittssj avatar Dec 12 '23 14:12 spittssj

@spittssj apologies, here is a public version https://github.com/jiafengkevinchen/logs-public/blob/6b2e96e482a2b389e182b1c8bbbc4d5023931fae/extract_tabular.R#L41

jonathandroth avatar Dec 12 '23 16:12 jonathandroth

Thanks @jonathandroth. I tried the code and it works well.

spittssj avatar Dec 26 '23 19:12 spittssj

Glad to hear!

On Tue, Dec 26, 2023, 2:33 PM Stephen Pitts SJ @.***> wrote:

Thanks @jonathandroth https://github.com/jonathandroth. I tried the code and it works well.

— Reply to this email directly, view it on GitHub https://github.com/rstudio/gt/issues/1310#issuecomment-1869734935, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE6EXFFTCEM5VZGA45JFZGTYLMRALAVCNFSM6AAAAAAXBIFCW6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNRZG4ZTIOJTGU . You are receiving this because you were mentioned.Message ID: @.***>

jonathandroth avatar Dec 27 '23 00:12 jonathandroth

I think this would be fixed if #1588 is merged?

olivroy avatar Jul 12 '24 17:07 olivroy

I think not quite, because the request was to have the output begin with \begin{tabular}, whereas the new feature appears to output \begin{table} \\n \begin{tabular}.

Just to clarify, the motivation for this request is that I find it much easier to handle creating tables locally in Latex--- because captioning, labeling, and desired placement are specific to the document. So my Latex document would have

\begin{table}[<placement options desired for this doc>]
\input{gt_output.tex}
\caption{<relevant caption for my table>}
\label{<label>}
\end{table} 

Of course, while you're modifying this code, it seems like it should be straightforward to omit the \begin{table} \\n part.

jonathandroth avatar Jul 12 '24 17:07 jonathandroth