【问题标题】:Center leaflet in a rmarkdown document在 rmarkdown 文档中居中传单
【发布时间】:2019-02-06 06:56:55
【问题描述】:

我想创建一个 html 文档,其中包含居中的传单小部件。

---
title: "Exemple"
author: "Antoine Bichat"
date: "31/08/2018"
output: html_document
---

```{r leaflet, fig.align="center"}
library(leaflet)

leaflet() %>%
  addTiles() %>% 
  addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
```

fig.align="center" 的第一个想法不起作用。

我找到了这个question,并根据我的情况对其进行了调整:

<style>
/* resize the widget container */
.leaflet { 
  width: 80% !important;
}

/* center the widget */
div.leaflet-control-container {
  margin: auto !important;
}
</style>

但如果我不想拥有 100% 的 out.width(我也不想这样做),那就行不通了。

也许我做错了...... 实际上我更喜欢 100% R/Rmarkdown 解决方案,但我对一切都持开放态度:)

【问题讨论】:

    标签: html css r leaflet r-markdown


    【解决方案1】:

    尝试将 CSS 代码 margin: auto 替换为 .html-widget

    ---
    title: "Exemple"
    author: "Antoine Bichat"
    date: "31/08/2018"
    output: html_document
    ---
    
    <style>
    .html-widget {
        margin: auto;
    }
    </style>
    
    ```{r leaflet, fig.align="center"}
    library(leaflet)
    
    leaflet() %>%
      addTiles() %>% 
      addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
    ```
    

    这将使每个 htmlwidget 居中。 你也可以放:

    <style>
    .leaflet {
        margin: auto;
    }
    </style>
    

    仅用于使传单居中。

    【讨论】:

    • 很好的答案!它也适用于使用传单依赖项的 tmap
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-20
    • 2014-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多