【问题标题】:Prevent pagebreak in kableExtra landscape table防止 kableExtra 横向表中的分页符
【发布时间】:2019-01-09 00:48:41
【问题描述】:

如何在 R Markdown(PDF 输出)中绘制横向表格而不导致插入分页符?

kableExtra 包中有函数landscape,但这会强制插入分页符。

示例:

R Markdown 中表格的正常行为是浮动以最小化文本的分解。

---
output: pdf_document
---

Some Text

```{r, echo=F, warning=F}
library(kableExtra)
knitr::kable(mtcars, format = "latex", caption = "A table")
```

More Text

风景

---
output: pdf_document
---

Some Text

```{r, echo=F, warning=F}
library(kableExtra)
knitr::kable(mtcars, format = "latex", booktabs = T, caption = "A table") %>%
  landscape()
```

More Text

【问题讨论】:

    标签: r latex r-markdown knitr kableextra


    【解决方案1】:

    你可以使用 LaTeX 包 realboxes 做你想做的事

    ---
    title: "Mixing portrait and landscape"
    output: pdf_document
    header-includes:
      - \usepackage[graphicx]{realboxes}
      - \usepackage{booktabs}
    ---
    
    Some text
    
    \Rotatebox{90}{
    ```{r, echo=FALSE, warning=FALSE}
    
    knitr::kable(mtcars, "latex", booktabs = TRUE)
    ```
    }
    More text
    

    这会生成单页 pdf,表格以横向显示。这种方法的问题在于它似乎不适用于标题。

    编辑你可以使用captionlatex包添加标题

    ---
    title: "Mixing portrait and landscape"
    output: pdf_document
    header-includes:
      - \usepackage[graphicx]{realboxes}
      - \usepackage{booktabs}
      - \usepackage{caption}
    ---
    
    Some text
    
    
    \begingroup 
    \captionsetup{type=table}
    \caption{A table}
    \Rotatebox{90}{
    
    ```{r, echo=FALSE, warning=FALSE}
    
    knitr::kable(mtcars, "latex", booktabs = TRUE)
    ```
    
    }
    \endgroup
    
    More text
    

    这会生成带有标题的横向表格

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-22
      • 1970-01-01
      • 2021-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多