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

如何在rmarkdown中将浮动图像(环绕文本)与居中标题对齐?

  •  1
  • Caterina  · 技术社区  · 6 年前

    到目前为止,这给了我想要的结果。

    <img align="right" src="images/cobre.png">
    

    但我想在图片下面放一个居中的标题。我该怎么做?

    1 回复  |  直到 6 年前
        1
  •  1
  •   tarleb    6 年前

    HTML输出可以通过CSS设置样式。样式可以直接包含在文本中,也可以放入单独的CSS样式表中。

    以下是如何使用内联CSS:

    ```{=html}
    <style type="text/css">
      .figure {
        float: right;
        text-align: center;
      }
    </style>
    ```
    
    ``` {r fig.cap = "Insert caption here", echo=FALSE}
    knitr::include_graphics("images/cobre.png")
    ```
    

    使用的优势 knitr::include_graphics 在原始HTML之上是 include_graphics 也适用于其他输出格式,如Word和PDF(尽管这些格式的图形不会正确对齐)。