Rendering gt tables correctly in pdf as well as html #6102
Replies: 5 comments 2 replies
-
@HaroldDMiller why are you creating another topic while we are discussing in #6084 ? How is this new discussion item different than the opened issue and also previous ones you opened
It does not help really to have you opened duplicated of a same topic, especially when we are trying to answer you already. Is there any difference in this question above ? And also I gave you an answer about the example above in the issue already #6084 (comment) |
Beta Was this translation helpful? Give feedback.
-
Sorry, it wasn't clear to me that people who wanted to weigh in on the desirability of adding this functionality to gt+Quarto would see it in the bug thread. |
Beta Was this translation helpful? Give feedback.
-
I appreciate that very much. I've spent many frustrating hours trying to tweak the LaTeX to do what I want with the text portion of the documents, and this issue with table formatting is the one "big" thing that has stymied me in the pdfs. I've also spent many hours trying to figure out whether the problem with the gt tables was my lack of skill or if there was some alternative I was missing (which is why I ended up going down the wkhtmltopdf rabbit hole). So please forgive me for my overkill in trying to get a good solution! |
Beta Was this translation helpful? Give feedback.
-
@HaroldDMiller, thanks for the feedback. I understand and share the desire to make the PDF table rendering work the same irrespective of the format. Unfortunately, the realities and requirements of PDF and HTML rendering make that a much harder problem than that of images. For example, converting the HTML element to an image (via a screenshotting package such as puppeteer) might seem like a feasible technical path, but it is not sufficient for the publishing requirements of a number of venues, which require tables to be formatted in LaTeX through text. As a result, the Unfortunately, the best solution right now is for |
Beta Was this translation helpful? Give feedback.
-
Thanks for that explanation, it's very helpful. The hours I've spent trying to wrangle LaTeX to do what I want gives me some understanding and a lot of sympathy for the challenges in making tables work well in pdfs. It is interesting that something as seemingly simple and universal as a nicely-formatted table is so difficult to create in any environment (other than Excel). It's hard to do it directly in Markdown, html, or LaTeX. One suggestion would be to add a short explanation like you've given me to the Quarto (and maybe gt) documentation so that people like me will know what limitations exist rather than having to "discover" them for ourselves... :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
My goal is to create a gt table in a .qmd file and be able to render the same file to either pdf or html and have the table look the same. Currently, when you render a qmd file with a gt table to pdf, the table loses much of the formatting that is included when it is rendered to html.
This problem exists when using gt to create tables, but not when using ggplot to create graphs. If I create a graph in ggplot, it will render exactly the same in html and pdf, without making any changes to the ggplot code. But if I create a table in gt, it will not render the same in pdf as it does in html. (See example below.) The only solution I've found is to use gtsave to save the gt output as a png file and then display the image of the table rather than the actual gt object. However, doing that means the table loses the responsive features of an html table in html, and different size tables appear to have different font sizes in the pdf because webshot2 produces all of the images at full page width.
gt is the best package by far for creating tables; others like kableextra work better in pdfs but don't have the same functionality as gt.
Here's an MRE that includes both a ggplot graph and a gt table based on the same data. If you render it in both html and pdf, the graph looks identical, but the gt table does not:
knitr:
opts_chunk:
echo: false
include: true
This is text.
Beta Was this translation helpful? Give feedback.
All reactions