Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combining Output Formats #2568

Open
franceskoi opened this issue Aug 12, 2024 · 2 comments
Open

Combining Output Formats #2568

franceskoi opened this issue Aug 12, 2024 · 2 comments

Comments

@franceskoi
Copy link

franceskoi commented Aug 12, 2024

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

@cderv
Copy link
Collaborator

cderv commented Aug 26, 2024

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

@franceskoi
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants