首页 > 解决方案 > 删除 Markdown 输出中的换行符

问题描述

我想将 a 的内容打印data.table到 R-Studio 的 Markdown 文档中。但是,输出有点宽,所以我减少了字体,如下所述:Code chunk font size in Rmarkdown with knitr and latex

然而,即使将字体减小到很小,尽管有足够的空间让列相邻,但换行符仍然存在。我想知道如何实现这一点。

---
title: "mwe"
output: pdf_document
---

```
{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(data.table)
dat <- data.table(id=1:5,num=31:35,text=c("a","b","c","d","here you can find some long text to artificially widen this text column and demonstrate the problem"))
```
Here is some text.

\tiny
```{r}
dat

```

输出2数据[5]

标签: rr-markdown

解决方案


检查?options并查找width控制每行打印列数的参数:

---
title: "mwe"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(data.table)
dat <- data.table(id=1:5,num=31:35,text=c("a","b","c","d","here you can find some long text to artificially widen this text column and demonstrate the problem"))
```

\tiny
```{r}
dat
```

```{r}
options(width = 120)
dat
```
 

在此处输入图像描述


推荐阅读