Перенос текста вокруг графиков в Markdown для экспорта документов Word - PullRequest
3 голосов
/ 27 мая 2020

В настоящее время существует нить, как обтекать участки текстом в Markdown , но это только для вязания на HTML. Мне нужно иметь возможность размещать текст рядом с сюжетом и выводить его в текстовый документ.

---
title: "Untitled"
author: "Your Name"
date: "May 27, 2020"
output: word_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown
```{r pressure, echo=FALSE, out.width= "65%", out.extra='style="float:right; padding:10px"'}
plot(pressure)
```


This is an R Markdown document. Markdown is a simple formatting syntax for authoring 
HTML, PDF, and MS Word documents. For more details on using R Markdown see 
<http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both 
content as well as the output of any embedded R code chunks within the document. You can 
embed an R code chunk like this:

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing 
of the R code that generated the plot.

Пожалуйста, сообщите.

1 Ответ

0 голосов
/ 01 июня 2020

Обычно мы можем определить некоторые глобальные стили для документа Word шаблона и передать его в новый документ Word, созданный с помощью R Markdown, но это не так просто, когда доходит до стилизации отдельных элементов .

Ниже приводится обходной путь для вашей проблемы с пакетом officedown Дэвида Гохеля. Уловка заключается в размещении содержимого в многоколоночном макете / блоке и настройке его аргументов widths и space:

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

Советы по работе с графиками / рисунками в текстовом выводе:
a) вам необходимо использовать fig.height и / или fig.width для масштабирования графиков / фигур;
b) рассмотрите возможность использования опции chunk crop = TRUE с функцией hook_pdfcrop() для обрезки / обрезки дополнительный белый край вокруг графика (см. @CL. SO answer здесь ).

Воспроизводимый .Rmd Пример:

---
title: "Untitled"
author: "Your Name"
date: "May 27, 2020"
output: officedown::rdocx_document
---

```{r setup, include=FALSE}
knitr::knit_hooks$set(crop = knitr::hook_pdfcrop)
knitr::opts_chunk$set(crop = TRUE,
                      echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

<!---BLOCK_MULTICOL_START--->
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

<!---CHUNK_COLUMNBREAK--->
```{r pressure, fig.height = 3.5, fig.width = 4.2, echo = FALSE}
plot(pressure)
```
<!---BLOCK_MULTICOL_STOP{widths: [2,4], space: 0.1}--->

## Lorem ipsum

<!---BLOCK_MULTICOL_START--->
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla eu pulvinar arcu, quis aliquam dui. In at cursus ante. Vestibulum non sagittis lacus. Duis vitae iaculis dui. Vivamus tempor, nibh ut pretium tempus, enim lorem dignissim quam, at euismod massa magna at magna. Sed facilisis dapibus diam nec volutpat. 

<!---CHUNK_COLUMNBREAK--->
Curabitur ligula quam, iaculis faucibus orci quis, vestibulum lobortis lectus. Suspendisse fringilla nisl pulvinar, laoreet tellus sed, sollicitudin tortor. Donec consequat congue erat in iaculis. Curabitur luctus tellus ut turpis iaculis, nec laoreet ligula scelerisque.
<!---BLOCK_MULTICOL_STOP{widths: [3,3], space: 0.2, sep: true}--->

Вывод:

enter image description here

Также вы можете включить слово шаблон с officedown:

---
output:
  officedown::rdocx_document:
    reference_docx: template.docx
---
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...