简体   繁体   English

在提取文档中调整图形大小/位置

[英]adjust figure size/placement in a distill document

I'm trying to put a small image into a distill document as part of a distill-based web site but having trouble with the placement (because I have a terrible mental model of what distill is doing and am not a CSS wizard).我试图将一个小图像作为基于 distill 的网站的一部分放入一个distill文档中,但在放置时遇到了问题(因为我对distill正在做什么有一个糟糕的心理模型,而且我不是一个 CSS 向导)。 I would like the picture to be set to the left of text, ideally with the text flowing around it.我希望图片被设置在文本的左侧,最好是文本在它周围流动。

Here is my first attempt:这是我的第一次尝试:

---
title: "Distill picture example"
site: distill::distill_website
---

<img align="left" src="django_small.png" width="50">
Here is some text that should be included, more than one line ... lorem ipsum when in the course of human events fourscore years and ten because I said so. (Make this a little longer so it will demonstrate wrapping?)

And the result (compiling with rmarkdown::render() ): the internal CSS machinery is overriding my requested width of 50 pixels and rendering the thing at full width instead.结果(使用rmarkdown::render()编译):内部 CSS 机制覆盖了我请求的 50 像素宽度,并以全宽呈现。

照片在此处设置为全角

Second attempt, where I explicitly tell distill that it should use the l-body-side layout:第二次尝试,我明确告诉distill它应该使用l-body-side布局:

---
title: "Distill picture example"
site: distill::distill_website
---

<div class "layout-chunk" data-layout="l-body side">
<img align="left" src="django_small.png" width="50">
</div>
Here is some text that should be included, more than one line ... lorem ipsum when in the course of human events fourscore years and ten because I said so. (Not long enough to demonstrate wrapping?)

用小图片渲染,但仍高于文本

That's closer, but I would prefer that the picture be set to the left of the text (not above it), and ideally that the text flow around the picture.那更接近,但我更喜欢将图片设置在文本的左侧(而不是它的上方),并且理想情况下文本围绕图片流动。 I have looked at the distill layout definitions , and this rstudio-distill issue which says that distill "does not support the inline floating image anymore" (but I would be OK with just setting the picture to the left, if I can't have it floating!), and this description of distill figure layouts , but I still can't get there.我已经看了看提制布局定义,和这个rstudio-提制问题,它说, distill “不支持内嵌浮动图像了。”(但我会OK只图像设置在左边,如果我不能有它漂浮了!),以及对提取图形布局的描述,但我仍然无法到达那里。

I imagine there could be some magical combination of CSS and/or a two-column, one-row table layout that would do what I want but it would probably take hours of trial and error (beyond the time I've already spent) to figure it out ...我想可能会有一些 CSS 和/或两列单行表格布局的神奇组合,可以满足我的要求,但可能需要数小时的反复试验(超出我已经花费的时间)才能想办法 ...

Found the answer in this blog post .这篇博文中找到了答案。

---
title: "Distill picture example"
site: distill::distill_website
---

:::float-image

```{r out.width='50px', out.extra='style="float:left; padding:10px"', echo=FALSE}
knitr::include_graphics("django_small.png")
```
Here is some text that should be included, more than one line ... lorem ipsum when in the course of human events fourscore years and ten because I said so. (Not long enough to demonstrate wrapping?)

:::

浮动图像


Wrapping it in a table also appears to have been easier/worked better than I expected.将它包装在表格中似乎也比我预期的更容易/工作得更好。 (I would still love to make the text wrap around the picture if possible ...) (如果可能的话,我仍然希望文字环绕图片......)

---
title: "Distill picture example"
site: distill::distill_website
---

<table>
<tr>
<td>
<img align="left" src="django_small.png" width="50">
</td>
<td>
Here is some text that should be included, more than one line ... lorem ipsum when in the course of human events fourscore years and ten because I said so. (Not long enough to demonstrate wrapping?)
</td>
</tr>

图片在文字左边

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM