问题描述
是否可以在rmarkdown pdf文档中放置一张宽表,以利用横向放置页面的额外宽度?
我在Stackoverflow上发现了以下相关问题,这些问题很有帮助,但不能解决huxtable
包的使用。
a)使用不同表包的宽表:xtable
,kableExtra
,Stargazer
:
Rotate a table from R markdown in pdf
b)旋转长桌(kableExtra
):
Rotating a table in PDF output from RMarkdown with more than one page
c)旋转pdf页面: Rstudio rmarkdown: both portrait and landscape layout in a single 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",235"),v5 = c("564",v6 = c("278",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")
```
\ newpage
\ blandscape
```{r wide-tbl-port-ldscp-page,results='asis'}
ht %>%
set_caption("Wide table in portrait document on landscape oriented page")
```
\ elandscape
以下表格中的结果:
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)