英文:
Quarto docx and columns
问题
我正在使用R / RStudio和Quarto,并发布到Word文档。我尝试使用这个HTML示例生成列输出:https://stackoverflow.com/questions/74162212/two-columns-layout-in-quarto。
当我使用这个示例并发布到HTML时,它正常工作,显示如下:
然而,当我尝试发布到Word时,我无法将文本放入列中,它总是变成这样:
我是不是在尝试Quarto无法完成的事情,还是需要一些秘密的技巧才能使其工作?
感谢任何/所有的帮助。
英文:
I'm using R / RStudio and Quarto and publishing to a Word document. I'm trying to generate column output using this example for HTML: https://stackoverflow.com/questions/74162212/two-columns-layout-in-quarto.
When I use this example and publish to HTML it works just fine and show like this:
However, when I try to publish to Word I fail to get the text into columns and it always ends up like this:
Am I trying to do something that Quarto can't do, or is there some secret sauce that's needed to make this work?
Thanks for any /all help.
答案1
得分: 0
以下是翻译好的部分:
"It is always better to also post your code, otherwise it is difficult to point out the mistakes. This code works for me:
---
format: docx
---
::: {layout-ncol=2}
**左列**
**右列**
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc finibus varius venenatis. Vivamus tincidunt, ex vitae sollicitudin ultrices, lectus massa sagittis eros, id interdum erat augue eget lacus. Vivamus nec nibh pulvinar, volutpat odio a, auctor arcu. Donec ac rutrum leo. Aliquam in diam pulvinar, aliquet mauris quis, laoreet lorem. Duis ut feugiat augue, sit amet tincidunt erat. Integer vitae arcu tristique, dapibus nibh at, rhoncus urna. Proin tincidunt massa eu ligula scelerisque feugiat. Vivamus et maximus tortor. Proin suscipit interdum erat in bibendum. Nulla facilisi. Duis commodo sapien aliquam erat pulvinar, a semper turpis porttitor. Nulla facilisi.
以及
Praesent quis ex odio. Integer a interdum nisl, a luctus orci. Aenean tincidunt ornare ligula vitae dapibus. Pellentesque vitae mauris consectetur mi aliquam efficitur. Nullam scelerisque turpis ante, eu bibendum quam commodo id. Mauris sagittis gravida arcu mollis congue. Etiam gravida tellus vestibulum turpis pretium, in eleifend ipsum euismod. Praesent vel velit eu dolor suscipit elementum. Morbi feugiat augue sapien, pretium venenatis ex venenatis egestas. Maecenas eget mi velit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque ornare sollicitudin quam, a consequat est sodales at. Mauris porttitor turpis aliquam lacinia faucibus. Integer at nisi egestas dolor hendrerit mollis.
:::
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/yGv2O.png"
<details>
<summary>英文:</summary>
It is always better to also post your code, otherwise it is difficult to point out the mistakes. This code works for me:
---
format: docx
---
::: {layout-ncol=2}
**Left column**
**Right column**
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc finibus varius venenatis. Vivamus tincidunt, ex vitae sollicitudin ultrices, lectus massa sagittis eros, id interdum erat augue eget lacus. Vivamus nec nibh pulvinar, volutpat odio a, auctor arcu. Donec ac rutrum leo. Aliquam in diam pulvinar, aliquet mauris quis, laoreet lorem. Duis ut feugiat augue, sit amet tincidunt erat. Integer vitae arcu tristique, dapibus nibh at, rhoncus urna. Proin tincidunt massa eu ligula scelerisque feugiat. Vivamus et maximus tortor. Proin suscipit interdum erat in bibendum. Nulla facilisi. Duis commodo sapien aliquam erat pulvinar, a semper turpis porttitor. Nulla facilisi.
and here
Praesent quis ex odio. Integer a interdum nisl, a luctus orci. Aenean tincidunt ornare ligula vitae dapibus. Pellentesque vitae mauris consectetur mi aliquam efficitur. Nullam scelerisque turpis ante, eu bibendum quam commodo id. Mauris sagittis gravida arcu mollis congue. Etiam gravida tellus vestibulum turpis pretium, in eleifend ipsum euismod. Praesent vel velit eu dolor suscipit elementum. Morbi feugiat augue sapien, pretium venenatis ex venenatis egestas. Maecenas eget mi velit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque ornare sollicitudin quam, a consequat est sodales at. Mauris porttitor turpis aliquam lacinia faucibus. Integer at nisi egestas dolor hendrerit mollis.
:::
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/yGv2O.png
</details>
# 答案2
**得分**: 0
我发现了一种使用[Office Open XML][1](OOXML)来构建.qmd文件中的部分的方法。
这是第一部分...
```{=openxml}
<w:p>
<w:pPr>
<w:sectPr>
<!-- <w:pgSz w:w="12240" w:h="15840"/> -->
<!-- <w:pgMar w:gutter="0" w:footer="720" w:header="720" w:left="1440" w:bottom="1440" w:right="1440" w:top="1440"/> -->
<w:cols w:space="720"/>
<w:jc w:val="both"/>
</w:sectPr>
</w:pPr>
</w:p>
```
在这里放置你的文本和图表,包括R代码。
然后使用以下代码关闭该部分...
```{=openxml}
<w:p>
<w:pPr>
<w:sectPr>
<w:type w:val="continuous"/>
<!-- <w:pgSz w:w="12240" w:h="15840"/> -->
<!-- <w:pgMar w:gutter="0" w:footer="720" w:header="720" w:left="1440" w:bottom="1440" w:right="1440" w:top="1440"/> -->
<w:cols w:space="720" w:num="2"/>
</w:sectPr>
</w:pPr>
</w:p>
```
这是一个完整的.qmd文件,将所有内容整合在一起:1)创建一个新的docx参考文档(将其命名为`custom-reference-doc.docx`),并将其放在你的主要.qmd目录中;2)打开参考文档并创建一个名为'Column Style'的新样式,使用Calibri Light和Block Text;3)创建一个新的(Word)Quarto文档;4)将这段代码复制/粘贴到RStudio中。
[1]: http://www.officeopenxml.com/WPsection.php
<details>
<summary>英文:</summary>
[Edited for clarity]
I found 'A' way to do this using [Office Open XML][1] (OOXML) to build the sections within the .qmd file
This is the first section part ...
```{=openxml}
<w:p>
<w:pPr>
<w:sectPr>
<!-- <w:pgSz w:w="12240" w:h="15840"/> -->
<!-- <w:pgMar w:gutter="0" w:footer="720" w:header="720" w:left="1440" w:bottom="1440" w:right="1440" w:top="1440"/> -->
<w:cols w:space="720"/>
<w:jc w:val="both"/>
</w:sectPr>
</w:pPr>
</w:p>
```
Put your text and graphs here, including R code.
And then close the section with this ...
```{=openxml}
<w:p>
<w:pPr>
<w:sectPr>
<w:type w:val="continuous"/>
<!-- <w:pgSz w:w="12240" w:h="15840"/> -->
<!-- <w:pgMar w:gutter="0" w:footer="720" w:header="720" w:left="1440" w:bottom="1440" w:right="1440" w:top="1440"/> -->
<w:cols w:space="720" w:num="2"/>
</w:sectPr>
</w:pPr>
</w:p>
```
Here is a full .qmd file that brings it all together: 1) Create a new docx reference-doc (call it `custom-reference-doc.docx`) and put it in your main .qmd
directory; 2) Open the reference-doc and create a new style called 'Column Style' with Calibri Light & Block Text; 3) Create a new (Word) Quarto Document; 4) Copy / paste this code into RStudio
---
title: "Word Document With Columns"
format:
docx:
reference-doc: custom-reference-doc.docx
number-sections: true
subtitle: 'Columns Be Done!'
abstract: '**Abstract:** Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'
subject: 'Columns in docx'
---
# Quarto
Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.
<br><br>
```{=openxml}
<w:p>
<w:pPr>
<w:sectPr>
<!-- <w:pgSz w:w="12240" w:h="15840"/> -->
<!-- <w:pgMar w:gutter="0" w:footer="720" w:header="720" w:left="1440" w:bottom="1440" w:right="1440" w:top="1440"/> -->
<w:cols w:space="720"/>
<w:jc w:val="both"/>
</w:sectPr>
</w:pPr>
</w:p>
```
## Columns with text and code
This is the inclusion of R code with surrounding text in the default text style.
```{r}
#| warning: false
library(ggplot2)
x <- ggplot(data = diamonds,
aes(x = price,
y = depth,
color = cut)) +
geom_point() +
labs(title = "Diamond Price v. Depth",
caption = "Diamonds Are A Girls Best Friend") +
geom_hline(yintercept = mean(diamonds$depth),
color = 'blue') +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5, colour = 'blue'),
plot.caption = element_text(colour = 'lightgray'))
```
Now the text style changes to a `custom-style` found in the included **reference-doc**, *custom-reference-doc.docx* - Calibri Light + Blocked Text.
::: {custom-style="Column Style"}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
::: {custom-style="Body Text"}
## Columns with text and Plot
This is the inclusion of an R plot with surrounding text in the default text style. Also, note the **out.width: 50%** in the code to keep the graph sized within the 2-columns. (Code is shown using Quarto's *Fenced Echo*.)
```{{r}}
#| warning: false
#| out-width: 50%
x
```
```{r}
#| echo: false
#| warning: false
#| out-width: 50%
x
```
:::
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
:::
</br></br>
```{=openxml}
<w:p>
<w:pPr>
<w:sectPr>
<w:type w:val="continuous"/>
<!-- <w:pgSz w:w="12240" w:h="15840"/> -->
<!-- <w:pgMar w:gutter="0" w:footer="720" w:header="720" w:left="1440" w:bottom="1440" w:right="1440" w:top="1440"/> -->
<w:cols w:space="720" w:num="2"/>
</w:sectPr>
</w:pPr>
</w:p>
```
[1]: http://www.officeopenxml.com/WPsection.php
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论