Rmarkdown中不同高度的垂直顶部对齐图形
我有一个 Rmarkdown 代码块,我想在其中显示两个不同高度的外部图形,并使它们在顶部垂直对齐。我正在输出一个 HTML 文档。
这是代码,
```{r, fig.show='hold', out.width="25%"}
include_graphics("leftfig.png")
include_graphics("rightfig.png")
它会生成中间对齐的并排图(不是实际图像,仅用作示例)。
但是,我希望这两个数字顶部对齐。我尝试了各种块选项组合,但没有找到与垂直对齐相关的Fig.align选项,也没有看到管理此选项的YAML标头的选项。
任何帮助将不胜感激。
I have an Rmarkdown code chunk where I want to display two external figures of different heights, and have them aligned vertically at the top. I am outputting an HTML document.
Here is the code
```{r, fig.show='hold', out.width="25%"}
include_graphics("leftfig.png")
include_graphics("rightfig.png")
This produces middle-aligned side-by-side plots (not the actual images, just used as an example).
However, I want these two figures top-aligned. I have tried various combinations of chunk options but I don't find fig.align options related to vertical alignment, nor do I see options for the YAML header that manages this.
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 CSS 的快速解决方法(应用于整个文档):
A quick workaround with CSS (applied to the entire document):
允许您在 html 输出文档中设置图形和/或图像的本地(而不是全局)垂直对齐的方法利用了链接到特定 HTML 的 CSS 样式的实用程序分配给任何 HTML
div
标记的类属性。在文档顶部定义 CSS 后,此
div
标记:...
;
可以包裹在您希望顶部对齐的任何/多个评估的 rmarkdown 代码块中。A method that allows you to set local, rather than global, vertical alignment of figures and/or images in an html output document exploits the utility of CSS styles linked to specific HTML class attributes assigned to any HTML
div
tag.Once the CSS is defined at the top of the document, this
div
tag:<div class="topalign">
...</div>
can be wrapped around any/multiple evaluated rmarkdown code chunks you wish to have top-aligned.