Multi-column RMarkdown pdf with tables: "! Package longtable Error: longtable not in 1-column mode."

Multi-column RMarkdown pdf with tables: "! Package longtable Error: longtable not in 1-column mode."

当RMarkdown文件包含Markdown表格时,是否可以将.rmd编织成多列.pdf?我正在尝试制作一个非常紧凑(小字体、最小间距等)的 pdf 以使用公式 sheet,但我无法将 .rmd 打印成包含多列的 pdf降价表。有解决此错误的方法吗?

---
title: ""
output:
  pdf_document
classoption:
- twocolumn
---

# Introduction

    | Model                                 | Formula                                                                               |
    | :------------------------------------ | :------------------------------------------------------------------------------------ |
    | Intercept Only                        | $\operatorname{Y_{i}} = \beta_{0} + \epsilon_{i}$                                     |
    | Simple linear regression              | $\operatorname{Y_{i}} = \beta_{0} + \beta_{1}x_{i} + \epsilon_{i}$                    |
    | Multiple linear regression            | $\operatorname{Y_{i}} = \beta_{0} + \beta_{1}x'_{i} + \epsilon_{i}$                   |
    | Interaction/Moderation                | $\operatorname{Y_{i}} = \beta_{0} + \beta_{1}x_1{i} + \beta_{2}x_2{i} + \epsilon_{i}$ |

RStudio 错误:

> ! Package longtable Error: longtable not in 1-column mode.

> Error: LaTeX failed to compile reprex.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See repre.log for more info.
> Execution halted

来自 reprex.log 的错误:

> ! Package longtable Error: longtable not in 1-column mode.

你可以用我的 huxtable 包来做到这一点:

---
title: ""
output:
  pdf_document
classoption:
- twocolumn
---

Two-column text goes here...

```{r, echo = FALSE}
library(huxtable)
ht <- tribble_hux(
  ~Model, ~Formula,
  "Intercept only", "$\operatorname{Y_{i}} = \beta_{0} + \epsilon_{i}$"
)

# to allow printing maths in column 2:
escape_contents(ht)[, 2] <- FALSE

ht

```

More two-column text goes here...

您可能还对 position(h) <- "wrapleft" 以及 font_sizewidth 等其他房产感兴趣。

您的 table 中似乎没有任何 r 特定代码。除了降价 table,您可以简单地添加适当的乳胶表格:

---
title: ""
output:
  pdf_document:
    keep_tex: true
classoption:
  - twocolumn
---

# Introduction

\begin{tabular}{|l|l|}
\hline
Model                                 & Formula                                                                               \
\hline
Intercept Only                        & $\operatorname{Y_{i}} = \beta_{0} + \epsilon_{i}$                                     \
Simple linear regression              & $\operatorname{Y_{i}} = \beta_{0} + \beta_{1}x_{i} + \epsilon_{i}$                    \
Multiple linear regression            & $\operatorname{Y_{i}} = \beta_{0} + \beta_{1}x'_{i} + \epsilon_{i}$                   \
Interaction/Moderation                & $\operatorname{Y_{i}} = \beta_{0} + \beta_{1}x_1{i} + \beta_{2}x_2{i} + \epsilon_{i}$ \
\hline
\end{tabular}