使滚动条出现在RMarkdown代码块(html视图) [英] Make Scrollbar appear in RMarkdown code chunks (html view)

查看:1185
本文介绍了使滚动条出现在RMarkdown代码块(html视图)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用RStudio和knitr制作了一个RMarkdown文档。我希望我的代码块打印时不会在我创建的html文件上打包文本。有没有一个选项我错过了停止代码的文本包装?到目前为止,我只找到了关于如何删除滚动条的问题,这让我觉得最近可能有些变化。 (RStudio版本0.99.892,R版本3.2.2)Thanks!

简单的示例RMarkdown文档。 (设置部分是默认设置):

  --- 
title:停止看起来糟糕的RMarkdown!
输出:html_document
---

```{r setup,include = FALSE}
knitr :: opts_chunk $ set(echo = TRUE)
```

####我希望在没有文字换行的情况下打印:

```{r}
x< - matrix(nrow = 3,ncol = 20,data = 1)
x
```

如果你运行它,你会看到矩阵x被分成2行。我希望它只是一行,你必须滚动才能看到整个事情。

  --- 
标题:停止看起来糟糕的RMarkdown!
输出:html_document
---

< style>
pre code,pre,code {
white-space:pre!important;
overflow-x:scroll!important;
word-break:keep-all!important;
word-wrap:首字母重要;
}
< / style>
$ b```{r setup,include = FALSE}
knitr :: opts_chunk $ set(echo = TRUE)
options(width = 200)
``` `

####我希望在没有文字换行的情况下打印:

```{r}
x< - matrix(nrow = 3,ncol = 20,data = 1)
x
```

更新版本的R markdown,您可以将< style> 标签替换为:

 ```{css} 
pre code,pre,code {
white-space:pre!important;
overflow-x:scroll!important;
word-break:keep-all!important;
word-wrap:首字母重要;
}
```


I am making an RMarkdown document using RStudio and knitr. I want my code chunks to print without wrapping text on the html file I create. Is there an option I am missing that stops text wrapping of code? So far I have only found questions about how to remove scrollbars, making me think that maybe something has changed recently. (RStudio Version 0.99.892, R Version 3.2.2) Thanks!

Simple example RMarkdown document. (The setup section is the default):

---
title: "Stop looking bad RMarkdown!"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

#### I want this to print without text wrapping:  

```{r}
x <- matrix(nrow = 3, ncol = 20, data = 1)
x
```

If you run that you will see that the matrix x is split into 2 lines. I want it to just be one line that you have to scroll along to see the whole thing.

解决方案

try:

---
title: "Stop looking bad RMarkdown!"
output: html_document
---

<style>
pre code, pre, code {
  white-space: pre !important;
  overflow-x: scroll !important;
  word-break: keep-all !important;
  word-wrap: initial !important;
}
</style>

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
options(width=200)
```

#### I want this to print without text wrapping:

```{r }
x <- matrix(nrow = 3, ncol = 20, data = 1)
x
```

NOTE that with more recent versions of R markdown you can replace the <style> tags with:

```{css}
pre code, pre, code {
  white-space: pre !important;
  overflow-x: scroll !important;
  word-break: keep-all !important;
  word-wrap: initial !important;
}
```

这篇关于使滚动条出现在RMarkdown代码块(html视图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆