“Quarto docx and columns” 可以翻译为 “Quarto docx 和列”。

huangapple go评论60阅读模式
英文:

Quarto docx and columns

问题

我正在使用R / RStudio和Quarto,并发布到Word文档。我尝试使用这个HTML示例生成列输出:https://stackoverflow.com/questions/74162212/two-columns-layout-in-quarto。

当我使用这个示例并发布到HTML时,它正常工作,显示如下:

“Quarto docx and columns” 可以翻译为 “Quarto docx 和列”。

然而,当我尝试发布到Word时,我无法将文本放入列中,它总是变成这样:

“Quarto docx and columns” 可以翻译为 “Quarto docx 和列”。

我是不是在尝试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:

“Quarto docx and columns” 可以翻译为 “Quarto docx 和列”。

However, when I try to publish to Word I fail to get the text into columns and it always ends up like this:

“Quarto docx and columns” 可以翻译为 “Quarto docx 和列”。

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}
    &lt;w:p&gt;
        &lt;w:pPr&gt;
            &lt;w:sectPr&gt;
                &lt;!-- &lt;w:pgSz w:w=&quot;12240&quot; w:h=&quot;15840&quot;/&gt; --&gt;
                &lt;!-- &lt;w:pgMar w:gutter=&quot;0&quot; w:footer=&quot;720&quot; w:header=&quot;720&quot; w:left=&quot;1440&quot; w:bottom=&quot;1440&quot; w:right=&quot;1440&quot; w:top=&quot;1440&quot;/&gt; --&gt;
                &lt;w:cols w:space=&quot;720&quot;/&gt;
                &lt;w:jc w:val=&quot;both&quot;/&gt;
            &lt;/w:sectPr&gt;
        &lt;/w:pPr&gt;
    &lt;/w:p&gt;
    ```

在这里放置你的文本和图表,包括R代码。

然后使用以下代码关闭该部分...

    ```{=openxml}
    &lt;w:p&gt;
        &lt;w:pPr&gt;
            &lt;w:sectPr&gt;
                &lt;w:type w:val=&quot;continuous&quot;/&gt;
                &lt;!-- &lt;w:pgSz w:w=&quot;12240&quot; w:h=&quot;15840&quot;/&gt; --&gt;
                &lt;!-- &lt;w:pgMar w:gutter=&quot;0&quot; w:footer=&quot;720&quot; w:header=&quot;720&quot; w:left=&quot;1440&quot; w:bottom=&quot;1440&quot; w:right=&quot;1440&quot; w:top=&quot;1440&quot;/&gt; --&gt;
                &lt;w:cols w:space=&quot;720&quot; w:num=&quot;2&quot;/&gt;
            &lt;/w:sectPr&gt;
        &lt;/w:pPr&gt;
    &lt;/w:p&gt;
    ```

这是一个完整的.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 &#39;A&#39; 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}
    &lt;w:p&gt;
        &lt;w:pPr&gt;
            &lt;w:sectPr&gt;
                &lt;!-- &lt;w:pgSz w:w=&quot;12240&quot; w:h=&quot;15840&quot;/&gt; --&gt;
                &lt;!-- &lt;w:pgMar w:gutter=&quot;0&quot; w:footer=&quot;720&quot; w:header=&quot;720&quot; w:left=&quot;1440&quot; w:bottom=&quot;1440&quot; w:right=&quot;1440&quot; w:top=&quot;1440&quot;/&gt; --&gt;
                &lt;w:cols w:space=&quot;720&quot;/&gt;
                &lt;w:jc w:val=&quot;both&quot;/&gt;
            &lt;/w:sectPr&gt;
        &lt;/w:pPr&gt;
    &lt;/w:p&gt;
    ```
Put your text and graphs here, including R code.

And then close the section with this ...

    ```{=openxml}
    &lt;w:p&gt;
        &lt;w:pPr&gt;
            &lt;w:sectPr&gt;
                &lt;w:type w:val=&quot;continuous&quot;/&gt;
                &lt;!-- &lt;w:pgSz w:w=&quot;12240&quot; w:h=&quot;15840&quot;/&gt; --&gt;
                &lt;!-- &lt;w:pgMar w:gutter=&quot;0&quot; w:footer=&quot;720&quot; w:header=&quot;720&quot; w:left=&quot;1440&quot; w:bottom=&quot;1440&quot; w:right=&quot;1440&quot; w:top=&quot;1440&quot;/&gt; --&gt;
                &lt;w:cols w:space=&quot;720&quot; w:num=&quot;2&quot;/&gt;
            &lt;/w:sectPr&gt;
        &lt;/w:pPr&gt;
    &lt;/w:p&gt;
    ```

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 &#39;Column Style&#39; with Calibri Light &amp; Block Text; 3) Create a new (Word) Quarto Document; 4) Copy / paste this code into RStudio



    ---
    title: &quot;Word Document With Columns&quot;
    format: 
        docx:
            reference-doc: custom-reference-doc.docx
            number-sections: true
    subtitle: &#39;Columns Be Done!&#39;
    abstract: &#39;**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.&#39;
    subject: &#39;Columns in docx&#39;
    ---
    
    # Quarto
    
    Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see &lt;https://quarto.org&gt;.
    
    &lt;br&gt;&lt;br&gt;
    
    ```{=openxml}
    &lt;w:p&gt;
        &lt;w:pPr&gt;
            &lt;w:sectPr&gt;
                &lt;!-- &lt;w:pgSz w:w=&quot;12240&quot; w:h=&quot;15840&quot;/&gt; --&gt;
                &lt;!-- &lt;w:pgMar w:gutter=&quot;0&quot; w:footer=&quot;720&quot; w:header=&quot;720&quot; w:left=&quot;1440&quot; w:bottom=&quot;1440&quot; w:right=&quot;1440&quot; w:top=&quot;1440&quot;/&gt; --&gt;
                &lt;w:cols w:space=&quot;720&quot;/&gt;
                &lt;w:jc w:val=&quot;both&quot;/&gt;
            &lt;/w:sectPr&gt;
        &lt;/w:pPr&gt;
    &lt;/w:p&gt;
    ```
    ## 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 &lt;- ggplot(data = diamonds, 
                aes(x = price,
                    y = depth,
                    color = cut)) +
        geom_point() +
        labs(title = &quot;Diamond Price v. Depth&quot;,
             caption = &quot;Diamonds Are A Girls Best Friend&quot;) +
        geom_hline(yintercept = mean(diamonds$depth),
                   color = &#39;blue&#39;) +
        theme_bw() +
        theme(plot.title = element_text(hjust = 0.5, colour = &#39;blue&#39;),
              plot.caption = element_text(colour = &#39;lightgray&#39;))
    ```
    
    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=&quot;Column Style&quot;}
    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=&quot;Body Text&quot;}
    ## 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&#39;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.
    :::
    
    &lt;/br&gt;&lt;/br&gt;
    
    ```{=openxml}
    &lt;w:p&gt;
        &lt;w:pPr&gt;
            &lt;w:sectPr&gt;
                &lt;w:type w:val=&quot;continuous&quot;/&gt;
                &lt;!-- &lt;w:pgSz w:w=&quot;12240&quot; w:h=&quot;15840&quot;/&gt; --&gt;
                &lt;!-- &lt;w:pgMar w:gutter=&quot;0&quot; w:footer=&quot;720&quot; w:header=&quot;720&quot; w:left=&quot;1440&quot; w:bottom=&quot;1440&quot; w:right=&quot;1440&quot; w:top=&quot;1440&quot;/&gt; --&gt;
                &lt;w:cols w:space=&quot;720&quot; w:num=&quot;2&quot;/&gt;
            &lt;/w:sectPr&gt;
        &lt;/w:pPr&gt;
    &lt;/w:p&gt;
    ```




  [1]: http://www.officeopenxml.com/WPsection.php

</details>



huangapple
  • 本文由 发表于 2023年6月12日 06:13:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76452715.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定