如何在RmarkDown生成的PDF中拟合控制台输出?

发布于 2025-02-02 11:39:10 字数 278 浏览 2 评论 0原文

​如何适合PDF中的广泛输出?

enter image description hereenter image description here

I am trying to print str(df) in pdf output of rmarkdown. How do I fit the wide output in pdf?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋凉 2025-02-09 11:39:10

对于PDF输出而言,包裹线路有点棘手。一个选项是使用乳胶软件包列表。我将使用mtcars数据集作为示例。您的rmarkDown应通过pandoc参数- listings这样的启用包:

---
title: "Test"
output:
  pdf_document:
    pandoc_args: --listings
    includes:
      in_header: preamble.tex
---

```{r, echo=FALSE, warning=FALSE, message=FALSE}
options(width = 300)
str(mtcars)
```

preamble.tex中,您在另一个文件中设置了该软件包的选项:

\lstset{
  breaklines=true
  basicstyle=\ttfamily
}

这是输出:

有关更多信息,请访问此链接: httpps ://bookdown.org/yihui/rmarkdown-cookbook/text-width.html

For PDF output is a bit trickier to wrap lines. One option is using the LaTeX package listings. I will use mtcars dataset as example. Your Rmarkdown should enable the package via the Pandoc argument --listings like this:

---
title: "Test"
output:
  pdf_document:
    pandoc_args: --listings
    includes:
      in_header: preamble.tex
---

```{r, echo=FALSE, warning=FALSE, message=FALSE}
options(width = 300)
str(mtcars)
```

In preamble.tex, you set an option of the package in a different file:

\lstset{
  breaklines=true
  basicstyle=\ttfamily
}

This is the output:

enter image description here

For more info check this link: https://bookdown.org/yihui/rmarkdown-cookbook/text-width.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文