Customized Table Output for Multiple Book Formats? #5236
-
I was really excited to see Quarto 1.3 include support for outputting multiple book formats simultaneously! My dissertation requires two outputs: a PDF document for official submissions, and a word document for advisor comments. I'd like to ensure consistency across output formats. However, I use {KableExtra} for table formatting for the PDF document, which as an HTML-type table does not translate into DOCX (even with YAML prefer-html: true). Is there a way to set custom options for table outputs such that, when outputting to multiple formats, different table outputs are used? For example, I'd like the following to happen:
As an alternate solution: is anyone aware of how to get KableExtra tables to properly output in DOCX format? A stopgap measuring could be saving the tables as a .png and loading them in as an image, but I'd ideally like the word doc version to be editable for advisor feedback. Any help would be appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You get several things to tackle here:
One solution is to do both at the same time by using a Table 📦 that will know how to create table for different outputs. If you really need to use kableExtra for HTML output, and want to use gt for other format, then you can conditional base on the output format using Either in one chunk using if (knitr::pandoc_to("html")) {
# do use kableExtra
} else {
# do use gt
} You could also do that with 2 chunks as shown in R Markdown cookbook recipes for LaTeX or HTML Conditional content is possible with Quarto too, but this will just filter what is included in output, and all the code are still executed. Could work well for your usage though. Hope it helps |
Beta Was this translation helpful? Give feedback.
You get several things to tackle here:
One solution is to do both at the same time by using a Table 📦 that will know how to create table for different outputs.
kableExtra knows that for HTML and PDF, but not for DOCX - from there doc, it does not support direct output to docx without copy pasting from HTML to word
So you need to use some 📦 that knows both format you want to target like flextable or gt. With those package you can write the same R code, including styling, and the package will know how to output to PDF and DOCX.
If you really need to use kableExtra for HTML output, and want to use gt for other format,…