You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rmarkdown生成PDF:横向模式无法全屏,aspectratio=169设置无效求助

R Markdown生成横向PDF无法占满全屏的问题解决

问题描述

用R Markdown生成PDF时,已设置横向模式但文档无法占满全屏,尝试添加aspectratio=169选项却无效。

可复现示例代码:

---
title: "Testing landscape and aspect ratio"
output: 
  pdf_document:
    number_sections: true
classoption:
  - landscape
  - "aspectratio=169"
header-includes:
   - \usepackage{dcolumn} 
documentclass: article
geometry: margin=1.5cm
---

```{r}
plot(rnorm(100))
环境信息:

sessionInfo()
R版本 4.3.2 (2023-10-31)
平台:x86_64-pc-linux-gnu (64-bit)
运行环境:Debian GNU/Linux 11 (bullseye)
矩阵运算:默认
BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.13.so; LAPACK版本 3.9.0
区域设置:
[1] LC_CTYPE=en_IN LC_NUMERIC=C LC_TIME=en_IN
[4] LC_COLLATE=en_IN LC_MONETARY=en_IN LC_MESSAGES=en_IN
[7] LC_PAPER=en_IN LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_IN LC_IDENTIFICATION=C

时区:Asia/Kolkata
时区代码来源:系统 (glibc)

已加载的基础包:
[1] stats graphics grDevices utils datasets methods base

通过命名空间加载(未附着):
[1] compiler_4.3.2

## 问题原因
`aspectratio`是**beamer文档类**的专属选项,你当前使用的`article`文档类并不支持该参数,所以设置无效。

## 解决方案
提供两种可行方案,根据你的文档场景选择:

### 方案1:改用beamer文档类(适合演示场景)
beamer是专门用于演示的LaTeX文档类,原生支持`aspectratio`参数,直接修改文档类并调整输出格式即可:
```yaml
---
title: "Testing landscape and aspect ratio"
output: 
  beamer_presentation:
    number_sections: true
classoption:
  - aspectratio=169
header-includes:
   - \usepackage{dcolumn} 
---

```{r}
plot(rnorm(100))
### 方案2:在article类下手动指定页面尺寸(适合常规文档)
如果需要继续使用`article`类,直接通过`geometry`参数定义16:9比例的横向纸张尺寸:
```yaml
---
title: "Testing landscape and aspect ratio"
output: 
  pdf_document:
    number_sections: true
classoption:
  - landscape
header-includes:
   - \usepackage{dcolumn} 
documentclass: article
# 指定16:9比例的纸张尺寸,同时保留边距设置
geometry: paperwidth=16cm,paperheight=9cm,margin=1.5cm
---

```{r}
plot(rnorm(100))
也可以使用英寸单位(对应常见的1080p演示尺寸):
`geometry: paperwidth=13.33in,paperheight=7.5in,margin=0.59in`

内容的提问来源于stack exchange,提问作者user2338823
相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 16:13:18