Skip to content

Combining Output Formats #2568

Open
Open

Description

@franceskoi

Is it possible that functions from the both bookdown and officedown are taken into account at the output? For instance, when I write this code (Version 1 of the .Rmd document):

---
title: "Analysis"

output: 
  officedown::rdocx_document:
    reference_docx: "reference.docx"
  bookdown::word_document2:
    reference_docx: "reference.docx"  
bibliography: references.bib
---


{r setup, include=FALSE}
knitr::opts_chunk$set(
	echo = TRUE,
	message = FALSE,
	warning = FALSE,
	out.width = NULL,
  out.height = NULL
)



# Header1

## Header2

### Header3

Lorem Ipsum Lorem Ipsum Lorem Ipsum

<br>

Lorem Ipsum:

-   Lorem Ipsum (Image: \@ref(fig:img1))

<br>




{r img1, echo=FALSE, message=FALSE, warning=FALSE, fig.height =2, fig.cap="Image 1", fig.id = "img1", fig.cap.style = "Image Caption"}
library(tidyverse)
library(readxl)
library(officer)   
library(flextable)
library(officedown)
library(ggplot2)
library(grid)
library(jpeg)

img <- readJPEG("rmarkdown_logo.jpg")

grid.raster(img)



<br>

#### Lorem Ipsum

Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum

<!---BLOCK_LANDSCAPE_START--->


{r w_height, echo=FALSE, message=FALSE, warning=FALSE, tab.cap="women height", tab.id = "rezultatiCM816", tab.cap.style = "Table Caption"}
height <- women$height
height




<!---BLOCK_LANDSCAPE_STOP--->


it ignores bookdown (it doesn't do automatic numeration of the chapters and it doesn't do me cross-referencing), but it makes me a landscape page from the officedown, but when I write this code (Version 2 of the .Rmd document):

---
title: "Analysis"

output: 
  bookdown::word_document2:
    reference_docx: "reference.docx" 
  officedown::rdocx_document:
    reference_docx: "reference.docx" 
bibliography: references.bib
---


{r setup, include=FALSE}
knitr::opts_chunk$set(
	echo = TRUE,
	message = FALSE,
	warning = FALSE,
	out.width = NULL,
  out.height = NULL
)



# Header1

## Header2

### Header3

Lorem Ipsum Lorem Ipsum Lorem Ipsum

<br>

Lorem Ipsum:

-   Lorem Ipsum (Image: \@ref(fig:img1))

<br>




{r img1, echo=FALSE, message=FALSE, warning=FALSE, fig.height =2, fig.cap="Image 1", fig.id = "img1", fig.cap.style = "Image Caption"}
library(tidyverse)
library(readxl)
library(officer)   
library(flextable)
library(officedown)
library(ggplot2)
library(grid)
library(jpeg)

img <- readJPEG("rmarkdown_logo.jpg")

grid.raster(img)



<br>

#### Lorem Ipsum

Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum

<!---BLOCK_LANDSCAPE_START--->


{r w_height, echo=FALSE, message=FALSE, warning=FALSE, tab.cap="women height", tab.id = "rezultatiCM816", tab.cap.style = "Table Caption"}
height <- women$height
height




<!---BLOCK_LANDSCAPE_STOP--->

it ignores officedown (it doesn't show me a landscape page), but it puts an automatic numeration for the chapters and cross-refferencing from bookdown.
So, it takes only what is first written. Is there a way to combine these two, so there can be shown an automatic numeration of the chapters and cross-refferencing from bookdown, as well as a landscape page from officedown?

I am sending the outputs for the Version 1 and Version 2 of the output Word documents, as well as the reference Word doc.
Version1.docx
Version2.docx
reference.docx

Activity

  1. cderv commented on Aug 26, 2024

    @cderv
    Collaborator

    I would advise to revise the rmarkdown basics about formats. rmarkdown::render() will only render one output format, that you can provide as an argument to the function, or using YAML and the first one will be used as default.

    If you want to combine feature from several output formats, you need to look into base_format document. Especially the combination of bookdown and officedown makes sense, and you should look at the doc.

    So basically

    output:
      officedown::rdocx_document:
        base_format: bookdown::word_document2

    You should look into more about the officeverse to see how you can achieve the different feature you need.

    Hope it helps

  2. franceskoi commented on Aug 31, 2024

    @franceskoi
    Author

    Thank you, I will try it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions