2

I am using Quarto in R to generate a docx output. However, I would like to have different page sizes (width and height) for individual pages, allowing me to customize the dimensions according to my needs. Currently, Quarto applies a consistent page size throughout the entire document.

I have explored the documentation and various options provided by Quarto but haven't found a straightforward solution for achieving this level of customization. Is there a way to control the page size on a per-page basis in Quarto's docx output?

Any guidance, code examples, or suggestions on how to approach this problem would be greatly appreciated. Thank you in advance!

  • Checkout [this question](https://stackoverflow.com/q/73784720/2425163). Modifying the dimensions of the `` element in the proposed filter should be enough to get you there. – tarleb May 21 '23 at 15:28
  • Is there a more straight foward answer? For example, I want to set my left margin at 0 so I can insert a image next to my title (since I'm not able to place images outside the document's margins). And then, I want to resume my initial margins specifications. Personally, I was very confused with the answer to the question you provided :( – Bileobio May 27 '23 at 15:18

1 Answers1

2

I tried several methods that did not work for me. The steps suggested in Tarleb's comment were the only ones that worked. I adapted the code to change the output from normal margins to narrow margins. To modify other things than margins, documentation can be found here.

  1. Create a .lua document (I personally use Visual Studio Code to do so)(and save it in the same directory as your Quarto/RMarkdown document) containing the following code:
local ooxml = function (s)
  return pandoc.RawBlock('openxml', s)
end

local end_narrow_section = ooxml [[
<w:p>
  <w:pPr>
  <w:sectPr>
    <w:pgMar w:top="722" w:right="722" w:bottom="722" w:left="722" w:header="567" w:footer="510" w:gutter="0"/>
    <w:cols w:space="708"/>
    <w:docGrid w:linePitch="360"/>
</w:sectPr>
  </w:pPr>
</w:p>
]]

function Div (div)
  if div.classes:includes 'narrow' then
    div.content:insert(end_narrow_section)
    return div
  end

end
  1. Then add a filter in the YAML header at the top of your Quarto/RMarkdown document, with the name of the file you have just created :
---
filters:
  - example.lua
---
  1. Wrap the part of the document that you want to have modified margins with the following code block:
::: narrow
This is an example
:::
  1. Render your document as a Word document as usual.

EDIT: Another way to proceed is to create a reference docx document with the desired margins. It is easier to implement, but the whole document will be formatted instead of being able to format only some parts. Just add the docx to the same folder and add the code below to the YAML header.

---
format : 
 docx :
  reference-doc: example.docx
---
ihecker
  • 21
  • 4