[英]How to fit console output in pdf generated by Rmarkdown?
For PDF output is a bit trickier to wrap lines.对于 PDF 输出,换行有点棘手。 One option is using the LaTeX package
listings
.一种选择是使用 LaTeX 包
listings
。 I will use mtcars
dataset as example.我将使用
mtcars
数据集作为示例。 Your Rmarkdown should enable the package via the Pandoc argument --listings
like this:您的 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)
```
In preamble.tex
, you set an option of the package in a different file:在
preamble.tex
中,您在不同的文件中设置包的选项:
\lstset{
breaklines=true
basicstyle=\ttfamily
}
This is the output:这是输出:
For more info check this link: https://bookdown.org/yihui/rmarkdown-cookbook/text-width.html有关更多信息,请查看此链接: https ://bookdown.org/yihui/rmarkdown-cookbook/text-width.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.