Chapter 29. Quarto Formats


So far, you’ve seen Quarto used to produce HTML documents. This chapter gives a brief overview of some of the many other types of output you can produce with Quarto.

There are two ways to set the output of a document:

  • Permanently, by modifying the YAML header:

    title: "Diamond sizes"
    format: html
  • Transiently, by calling quarto::quarto_render() by hand:

    quarto::quarto_render("diamond-sizes.qmd", output_format = "docx")

    This is useful if you want to programmatically produce multiple types of output since the output_format argument can also take a list of values:

      "diamond-sizes.qmd", output_format = c("docx", "pdf")

Output Options

Quarto offers a wide range of output formats. You can find the complete list on the Quarto documentation on all formats. Many formats share some output options (e.g., toc: true for including a table of contents), but others have options that are format specific (e.g., code-fold: true collapses code chunks into a <details> tag for HTML output so the user can display it on demand; it’s not applicable in a PDF or Word document).

To override the default options, you need to use an expanded format field. For example, if you wanted to render an HTML document, with a floating table of contents, you’d use:

    toc: true
    toc_float: true

You can even render to multiple outputs by supplying a list of formats:

    toc: true
    toc_float: true
  pdf: default
  docx: default ...

Get R for Data Science, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.