spgarbet / tangram

Table Grammar package for R
66 stars 3 forks source link

Latex output, missing includes, malformed (wide) tables, numbered tables #68

Open bogie opened 4 years ago

bogie commented 4 years ago

Hey its me again :).

First of all these are not breaking bugs for me, but I wanted to document them for you since they have not been reported yet, I will probably render my tables and figures manually. Although if you have a convenient way to render a tangram table to a .png directly I would love to know!

I have been trying to get Latex rendering to work with tangram and encountered three problems:

  1. the .tex file is missing includes
  2. the width of tables exceeds the maximum page width when using tables with many columns(9).
  3. there seems to be a automatic numbering of tables

as per (1): I am using tinytex with latex_engine: xelatex. The .tex file is missing includes for "longtable","relsize" and the "xcolor" include is malformed(required for rowcolors), it should say:

\usepackage[table]{xcolor}

rather than \usepackage{xcolor}

I have no idea how these includes are handled in the latex rendering engine and could not find anything in your code, otherwise I would love to provide possible fixes.

as per (2): Tables are properly aligned with a left page-margin with the text/headings, maybe breaking that margin or reducing it could alleviate the issue? Tables with up to 5 columns seem fine. This is not a breaking bug for me personally since the finished tables should have only 5-6 columns but

as per (3): I guess the relevant code is in: https://github.com/spgarbet/tangram/blob/master/R/render-latex.R#L307 This is not a breaking bug for me and I can understand that this is probably wanted behaviour, however since it doesn't happen in html_document I was a bit surprised at first.

Thanks for your effort of creating this package, it made my life a lot easier already :)

spgarbet commented 4 years ago

Thanks for the input. The conversion to longtable has been more effort than I thought it would be and there are a lot of warts I'd like to shave off. I'd like it to be a switch for longtable or not, and maybe I'll get there. I had some struggles with the different LaTeX engines and had to get some reports out, so I focused on one for the time being. This helps a lot, and I'd love to have it working for all. I think I can fix these things easily. (I also accept pull requests....)

bogie commented 4 years ago

Which LaTeX engine do you propose to use?

spgarbet commented 4 years ago

I'm using XeLaTeX, but my goal is that one should be able to use any of them.

spgarbet commented 4 years ago

When doing Rmd the \usepackage statements all come from the RStudio template. I think the xcolor issue you see is in their template. There is no way that I know of to add packages to rendering LaTeX since tangram is downstream of when that is generated by knitr. They make changes to their templates from time to time and I'm left scrambling to catch up. See https://github.com/spgarbet/tangram-vignettes/blob/master/example.Rmd for including extra from Rmd, and a currently working example. One can also in an Rmd document specify a different template to use rather than the default.

If you're using the fragment=FALSE command, I need to test that again since so much has changed. I've added the required ones to that piece of the code in my last commit.

The relsize argument can resize a table a bit if LaTeX is the only desired output. The cgroup.just argument specifies the layout in the LaTex.

spgarbet commented 1 year ago

It's frustrating the way pandoc keeps changing the target for LaTeX. I opened a few tickets to get this changed and fixed and most have not been addressed.

bogie commented 1 year ago

Nice! In the end I just used the docx output, so it worked out for me and it is what most journals expect anyway. Btw I published my paper and mentioned your package in the methods :). Thanks again, tangram really allowed me to create multiple versions for summary statistics in quick succession.

spgarbet commented 1 year ago

Great!! If you have use cases or suggestions I'm open to ideas.