Wrapping text around a right-floated image in RMarkdown document.

I'm trying to wrap text around a right-floated image. It will be a page on a Distill website. I'm working in RStudio.

Here is the text:

Vivamus venenatis egestas eros ut tempus. Vivamus id est nisi. Aliquam molestie erat et sollicitudin venenatis. In ac lacus at velit scelerisque mattis.

Vivamus venenatis egestas eros ut tempus. Vivamus id est nisi. Aliquam molestie erat et sollicitudin venenatis. In ac lacus at velit scelerisque mattis.

```{r out.width='30%', out.extra='style="float:right; padding:10px"'}
knitr::include_graphics("images/CXR.jpg")
```

Vivamus venenatis egestas eros ut tempus. Vivamus id est nisi. Aliquam molestie erat et sollicitudin venenatis. In ac lacus at velit scelerisque mattis.

This is the resultant image:


The text is obviously not wrapping.

How do I achieve this ?

Thanks!

Howard

I believe this is a specificity of the distill framework. You need to customize further the CSS.
If you look at the source of the HTML page, you'll see that the image and the following paragraph are not in the same div. Which impact the way the float works. If you use html_document your CSS should work for example. This is because of the special features for figures:

It seems that adding a div for your text and your figure will get you the expected result. You can add a div using Pandoc fenced div feature for custom block, useful for customizing a document

---
title: test
output: 
  distill::distill_article: default
--- 

Vivamus venenatis egestas eros ut tempus. Vivamus id est nisi. Aliquam molestie erat et sollicitudin venenatis. In ac lacus at velit scelerisque mattis.

Vivamus venenatis egestas eros ut tempus. Vivamus id est nisi. Aliquam molestie erat et sollicitudin venenatis. In ac lacus at velit scelerisque mattis.

::: {.floatting}

```{r out.width='30%', out.extra='style="float:right; padding:10px"'}
knitr::include_graphics("Rlogo.svg")
```

Vivamus venenatis egestas eros ut tempus. Vivamus id est nisi. Aliquam molestie erat et sollicitudin venenatis. In ac lacus at velit scelerisque mattis.
:::

You can further customize looking at more precise CSS for this kind of task.

Hope it helps

2 Likes

@cderv

That works.

Thanks so much!

Howard

1 Like

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.