【问题标题】:How can I change the number of columns several times in an R Markdown pdf document?如何在 R Markdown pdf 文档中多次更改列数?
【发布时间】:2017-11-03 15:48:28
【问题描述】:

我正在使用 R Markdown 创建一个 .pdf。我想要一段两列格式的文本,然后用一个占据整个页面宽度的图表(或表格、照片等),然后返回两列文本。我是 Markdown / LaTex / Pandoc 的新手,我不知道该怎么做。

@AlisonShelton 的This answer 似乎是我想要的,但是当我运行它时,我在 RStudo R Markdown 控制台中收到此错误:

!未定义的控制序列。
l.87 \btwocol
pandoc.exe:生成 PDF 时出错
错误:pandoc 文档转换失败,错误 43

我已经成功使用@scoa 的this method 制作了一个两列的.pdf,但我不知道如何使用它在一列和两列之间来回切换。

这是一些用于测试目的的示例代码

    ---
    title: "Test"
    output: pdf_document
    ---

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

    ## Two columns of text

    This seciton should be in two column format.
    Here are a bunch of ? to make it longer: ???????????????????????????????????????????????????????????????????????????????
    ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
    ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
    ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????

## Once column section. 
This part should be the whole page width
```{r plot}
plot(rnorm(20),rnorm(20))
```

## Now 2 columns again
This section should go back to two columns  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

【问题讨论】:

    标签: r r-markdown


    【解决方案1】:

    首先,您可以做的是,如您所说,将pandoc_args: ... 添加到您的 YAML 标头中。其次,有一些 LaTeX 解决方案(如 thisthis one)不适用于 RMarkdown。到目前为止,我发现的唯一方法是使用 \onyecolumn / \twocolumn - 只是有分页符的缺点。但也许你可以忍受它,直到有更好的解决方案。

    ---
    title: "Test"
    output:
      pdf_document: 
        pandoc_args: [
          "-V", "classoption=twocolumn"
        ]
      html_document: default
    header-includes:
    - \usepackage{lipsum}  # just used for producing example text in document
    ---
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
    ```
    
    ## Two columns of text
    \lipsum[1-7]
    \onecolumn
    
    ## Once column section. 
    This part should be the whole page width
    ```{r plot}
    plot(rnorm(20),rnorm(20))
    ```
    \lipsum[1]
    \twocolumn
    
    ## Now 2 columns again
    This section should go back to two columns
    \lipsum
    
    \begin{table*}
    This is nice, but won't work with R chunks or headers. And you'll have to format with LaTeX code (e.g. \textbf{Foo blaah}).
    \lipsum[1]
    \end{table*}
    \lipsum
    

    【讨论】:

    • 谢谢!。分页符是一个真正的缺点,但至少这是一个选项。
    猜你喜欢
    • 1970-01-01
    • 2021-01-08
    • 2014-08-27
    • 1970-01-01
    • 1970-01-01
    • 2022-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多