R markdown flexdashboard 文本边距

R markdown flexdashboard text margins

如何在 rmarkdown flexdashboard 文档中为文本创建漂亮的边距? Their manual site 是使用 flexdashboard 创建的,文本很好地跨越了中间的可读区域,没有到达屏幕的两侧。边距可以很好地适应浏览器 window 的宽度。尽管多次尝试指定 {data-width}{data-padding},但我无法重现此行为。我的文本总是从一边横跨到另一边,这在宽屏浏览器中看起来不太好 window。示例 Rmd 文件:

---
title: "Text width problem"
output:
  flexdashboard::flex_dashboard:
    orientation: rows
---

I'd like this text to have margins on the sides. I'd like this text to have 
margins on the sides. I'd like this text to have margins on the sides. I'd 
like this text to have margins on the sides. I'd like this text to have 
margins on the sides. I'd like this text to have margins on the sides. I'd 
like this text to have margins on the sides. I'd like this text to have 
margins on the sides. I'd like this text to have margins on the sides. I'd 
like this text to have margins on the sides. I'd like this text to have 
margins on the sides. I'd like this text to have margins on the sides. I'd 
like this text to have margins on the sides. I'd like this text to have 
margins on the sides.

通过使用 CSS 设置文档样式。这里我们把文档的整个主体都缩小了。

---
title: "Text width problem"
output:
  flexdashboard::flex_dashboard:
    orientation: rows
---

<style>
body {
  padding: 0px 200px 0px 200px;
}
</style>


This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides. This text has margins on the sides.

另一种方法是用 div 容器用特定的 ID 包裹您的文本,例如

<div id="myText">
....
</div>

并修改

<style>
#myText {
  width: 300px;
  margin: auto;
}
</style>