代码之家  ›  专栏  ›  技术社区  ›  abichat

在标记文档中居中放置传单

  •  2
  • abichat  · 技术社区  · 6 年前

    我想创建一个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>
    

    out.width 100%(我不想这么做),这是行不通的。

    或者我做错了。。。 R / Rmarkdown 但我愿意接受一切:)

    1 回复  |  直到 6 年前
        1
  •  11
  •   Colin FAY    6 年前

    试试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")
    ```
    

    enter image description here

    它将成为所有htmlwidget的中心。 您还可以:

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

    仅用于将传单居中。