1

有没有办法在 rmarkdown pdf 文档中放置一个宽表,以利用横向页面的额外宽度?

我在 Stackoverflow 上发现了以下相关问题,这些问题很有帮助,但没有解决huxtable包的使用问题。

a) 使用不同表格包的宽表格:xtable, kableExtra, Stargazer: 从 pdf 中的 R markdown 旋转表格

b) 旋转长表 ( kableExtra): 旋转 RMarkdown 输出的 PDF 中的多页表

c) 旋转 pdf 页面: Rstudio rmarkdown:一个 PDF 中的纵向和横向布局

横向宽表pdf

宽表在以横向格式设置的 pdf 中运行良好。

---
title: "wide table in landscape pdf rmarkdown"
output: 
  pdf_document:
    fig_caption: yes
geometry: margin=2cm
classoption: landscape
---


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

```{r wide-table, include=FALSE}
    wide_table <- data.frame(id = 1:3,
             g1 = c("some text", "some more text", "altogether more text"),
             g2  = c("a descriptive var with lots of words", "short desc", "A typical description"),
             qnt = c(2, 100, 37),
             uom = c("nr", "m", "m2"),
             v1 = c("1,256", NA, "123"),
             v2 = c("25", "6,555", "723"),
             v3 = c("12", "699", "6"),
             v4 = c("9,656",  "491", "6,235"),
             v5 = c("564", NA, "123"),
             v6 = c("278", NA, NA),
             v7 = c("10", "25,365", "1524"),
             v8 = c(22.4, 33.5, 45.8),
             v9 = c(1.25, 45.6, 0.36))

header_names <- c("ID", "Main heading", "Some descriptive text", "A Number", "Unit", paste("Variable", 1:9))

ht <- 
  huxtable(wide_table) %>%
  set_width(1) %>% 
  set_col_width(c(1/17, 2/17, 3/17, rep(1/17, 11))) %>% 
  set_contents(row = 1, col = 1:14, value = header_names) %>% 
  set_font_size(everywhere, everywhere, 8) %>% 
  theme_article()
```


```{r ht-wide-df, results='asis'}
    ht %>% 
      set_caption("Wide table in landscape document")
```

结果很好:这就是我希望表格在带有横向页面的纵向 pdf 中的样子。

在此处输入图像描述

纵向宽桌pdf

在纵向页面上

宽表格适合纵向,但标题重叠,表格开始难以阅读。

在横向页面上

宽表的尺寸与纵向相同,但存在相同的问题:

  • 标题重叠和
  • 表格开始难以阅读。

表格不会拉伸以适应横向页面。

我的问题:有没有办法操纵表格以适应横向页面中的完整空间,例如文档全部设置为横向的示例。

---
title: "wide huxtable in portrait with landscape page"
output: pdf_document
geometry: margin=2cm

header-includes:
- \usepackage{pdflscape}
- \newcommand{\blandscape}{\begin{landscape}}
- \newcommand{\elandscape}{\end{landscape}}
---

```{r wide-tbl-port, results='asis'}
    ht %>% 
      set_caption("Wide table in portrait document")
```

\新页面

\平淡无奇

```{r wide-tbl-port-ldscp-page, results='asis'}

ht %>% 
  set_caption("Wide table in portrait document on landscape oriented page")

```

\风景

结果如下表:

在此处输入图像描述 在此处输入图像描述

4

0 回答 0