One report, three formats
The boss wants a web page, a PDF for printing and a Word file to edit. With Quarto, one file makes all three. We write once, and the numbers and charts are the same in every version.
What we need
- Quarto 1.4 or newer (it comes with RStudio)
- R with the knitr and rmarkdown packages
- One .qmd file
List the formats at the top
Save this as report.qmd. The format part lists all three. Typst makes the PDF without installing a big LaTeX system.
---
title: "Heat requests this winter"
author: "Zobaer Ahmed"
format:
html: default
typst: default
docx: default
---Write the report under it
Words, code and charts go below the top part. The same code chunk makes the chart in every format.
## What we found
Requests went up when the weather turned cold.
```xcy
#| echo: false
plot(cars)
```Make all three at once
In the Terminal (not the R console), this makes report.html, report.pdf and report.docx side by side.
quarto render report.qmdOr just one of them
Use --to when we only need one.
quarto render report.qmd --to docxKitchen tip: the habit that prevents this
Keep charts and tables in code, not pasted in. Then every format always shows the same, current numbers.
Three common mix-ups
- Running quarto render in the R console. It goes in the Terminal tab (or use quarto::quarto_render() in R).
- Interactive charts work on the web page only; PDF and Word need a plain picture.
- Wide tables that fit the web page get cut off in PDF. Shrink the font or split the table.
Quick check
Which part of report.qmd decides which files we get?
- format: html, typst, docx
- quarto render report.qmd
- --to docx for just one
- charts in code, not pasted
Keep the recipe card
A one-picture summary to pin next to a screen or send to a friend who is stuck on the same thing.
Trying this on other data? Check the row counts and results before and after each step. Package versions change, so if something here works differently, please tell us. Every output on this page comes from running the code above in R; please cross-check before relying on it for our work.