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.
截至 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)
其他东西会将 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)