ms-wordr-markdowndocxline-numbers

rMarkdown: compile word docx document with line numbers


I am trying to produce a document with rMarkdown code that will render a word docx document that contains continuous line numbers. This is to facilitate workflow for publication submissions where line numbers are often requested.

I have tried using a style docx document with line numbers that was originally rendered from rMarkdown and subsequently edited to change heading style and line numbers. Heading style does change according to that style document but line numbers are not introduced. Desperate latex package use also didn't work in yaml as below.

---

output:
  pdf_document:
    citation_package: natbib
    keep_tex: yes
    fig_caption: yes
    latex_engine: pdflatex
  word_document: 
    reference_docx: ele_style.docx
geometry: margin=1in
fontfamily: mathpazo
fontsize: 11pt
mainfont: Times New Roman
linespread: 2
header-includes: 
  -\usepackage{helvet}
  -\usepackage{setspace}
  -\doublespacing
  -\usepackage{lineno}
  -\linenumbers
bibliography: LitRev_Bibli.bib
biblio-style: Zotero/styles/ecology-letters.csl
---

Does anyone know how to render line numbers into word docx from rMarkdown?


Solution

  • Go to your word template layout -> line numbers -> line numbering options and set your options. Then click SetAsDefault. It will ask if you want it set as the default for all documents using this template. Answer 'yes'.