增加整个HTML Rmarkdown输出的宽度

Nat*_*lly 14 html margins rstudio r-markdown

我希望增加HTML Rmarkdown输出的总宽度.

从Rmarkdowns生成PDF文档时,可以选择在Rmd的YAML部分设置边距(例如geometry:margin = .5in).

我正在为HTML文档寻找类似的东西.以下链接是我的问题的一个很好的例子:https://rstudio.github.io/DT/extensions.html

正如您在该html网页上看到的那样,数据表的左侧和右侧有很多空白区域.有没有办法减少这个边距空间,从而增加数据表的宽度?

谢谢

Ras*_*sen 15

将它放在rmarkdown文档的顶部(但在元数据部分下方):

<style type="text/css">
.main-container {
  max-width: 1800px;
  margin-left: auto;
  margin-right: auto;
}
</style>
Run Code Online (Sandbox Code Playgroud)

不要把它放在一个块中,而是作为纯文本.它应该将内容区域的最大宽度设置为1800px.

  • **仅当我按照 [this answer](/sf/answers/2686169251/) 中的建议将 `!important` 规则添加到 `max-width` 定义** 时才有效。但是使用该规则 [似乎不好的做法](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#The_!important_exception),那么还有另一种方法吗? (3认同)
  • 它可以在我的机器上运行,无需添加任何其他内容。在 Chrome、Explorer 和 Edge 中进行了测试,它适用于所有这些版本。使用 rmarkdown 1.6 和 R 3.4.2。 (3认同)
  • 如果我将 `.main-container` 更改为 `div.main-container`,它对我有用。已经有这种定义,所以我想它被覆盖了。 (3认同)

zer*_*eck 6

截至 rmarkdown 2.10,此处提出的解决方案或链接的答案没有得到任何结果。我无法让它与 .rmd 文件中的内联 css 一起使用。然而,当在 .rmd 文件夹中添加一个 doc.css 文件并仅包含以下条目时,它确实立即起作用:

div.main-container {
  max-width: 1600px !important;
}
Run Code Online (Sandbox Code Playgroud)

并将其添加到 yaml 标头中,如下所示:

---
title: asd
author: abc
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
  html_document:
    toc: true
    toc_float: true
    toc_depth: 6
    mathjax: null
    css: doc.css
---
Run Code Online (Sandbox Code Playgroud)


Vit*_*hKa 6

其他东西会将 max-width 插入到 html 输出中,因此您需要标记宽度!important才能使其工作


<style type="text/css">
.main-container {
  max-width: 100% !important;
  margin: auto;
}
</style>
Run Code Online (Sandbox Code Playgroud)


小智 -3

正如这里所解释的,您需要使用以下代码:

datatable(..., options = list(autoWidth = TRUE,columnDefs = list(list(width = '200px', targets = c(1, 3)))))
Run Code Online (Sandbox Code Playgroud)