officer support

library(officedown)
library(officer)

Introduction

Package {officer} provides functions to produce document blocks and runs elements. They can be used in the R Markdown document to produce elements with formatting not available by default with R Markdown and pandoc:

Features

---
author: 'Bruce'
date: '0189-12-27'
output: 
  officedown::rdocx_document:
      mapstyles:
        Normal: ['First Paragraph', 'Author', 'Date']
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(officedown)
library(officer)
fp <- fp_par(text.align = "center", padding.top = 120)
ft <- fp_text(font.size = 12, bold = TRUE, color = "#C32900", font.family = "Cambria")
```

## Chunk outputs

The package `r ftext("officedown", ft)` is great. 

This is a Word field, the file size is `r run_seqfield("FILESIZE \\k \\* MERGEFORMAT")` Kb. 

## Paragraph settings

This text is centered `r fp_par(text.align = "center")`.

## Section definitions

<!---BLOCK_MULTICOL_START--->

This text is on column 1. This text is on column 1.
This text is on column 1. This text is on column 1.
This text is on column 1. This text is on column 1.
This text is on column 1. This text is on column 1.
This text is on column 1. This text is on column 1.`r fp_par(text.align = "justify")`
`r run_columnbreak()`

This text is on column 2.
This text is on column 2.
This text is on column 2.
This text is on column 2.
This text is on column 2.
This text is on column 2.`r fp_par(text.align = "justify")`

<!---BLOCK_MULTICOL_STOP{widths: [3,3], space: 0.2, sep: true}--->


<!---BLOCK_LANDSCAPE_START--->

This is a landscape section.`r fp`

<!---BLOCK_LANDSCAPE_STOP--->


This is a custom section using `block_section`.`r fp`

```{r}
ps <- prop_section(
  page_margins = page_mar(bottom = 1, top = 2, left = 1.5),
  type = "oddPage"
)
block_section(ps)
```

We are back on default section.`r fp`

Tags

Tags (as HTML comments) have been designed to be less verbose and easier to use; for landscape pages, for multi-columns sections and for tables of contents.

Tables of content

The following will be transformed as a table of content:

<!---BLOCK_TOC--->

`BLOCK_TOC` tag is using R function `officer::block_toc`. You can use its arguments.

<!---BLOCK_TOC{level: 2}--->

> The parameters are defined in a yaml string. Each item in the list is a list
> of key/value pairs defined with `key: value` form (the colon must be followed
> by a space).

<!---BLOCK_TOC{style: 'Table Caption'}--->

### Add external docx

The following will pour the content of an external docx file into the 
produced document:

<!---BLOCK_POUR_DOCX{file: 'path/to/docx'}--->

BLOCK_POUR_DOCX tag is using R function officer::block_pour_docx.

Sections blocks

Tags for section blocks need to be used in pairs, BLOCK_LANDSCAPE_START and BLOCK_LANDSCAPE_STOP, BLOCK_MULTICOL_START and BLOCK_MULTICOL_STOP.

landscape orientation

The following will be in a separated section with landscape orientation

<!---BLOCK_LANDSCAPE_START--->

Blah blah blah.

<!---BLOCK_LANDSCAPE_STOP--->

section with columns

The following will be in a separated section with 2 columns:

<!---BLOCK_MULTICOL_START--->

Blah blah blah on column 1.

<!---CHUNK_COLUMNBREAK--->
Blah blah blah on column 2.


<!---BLOCK_MULTICOL_STOP{widths: [3,3], space: 0.2, sep: true}--->

These are the only tags implemented for sections. If these do not satisfy your needs, define any section by using officer::block_section in knitr code chunks. Remember a section affects preceding paragraphs or tables; i.e. a section starts at the end of the previous section (or the beginning of the document if no preceding section exists), and stops where the section is declared. Usually, starting with a continous section and ending with the section you defined is enough.

Illustrations

Caption from scratch