如何在 Rmarkdown knit-to-pdf 文档中的图表周围环绕文本? [英] How to wrap text around charts in a Rmarkdown knit-to-pdf document?

查看:14
本文介绍了如何在 Rmarkdown knit-to-pdf 文档中的图表周围环绕文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Rmarkdown 文档,它编织成 PDF

I have an Rmarkdown document which knits to PDF Text not wrapping around chart

My wish is for the white space to the right of the chart be filled by text rather than having all that white space. I have tried the following with the impression that the [h] qualifier will "float" the image with the text wrapping around it. However as you can see from the linked image, this is not the case.

egin {figure}[h]
includegraphics[width=8cm] {plot.pdf} 
end {figure} 
When asked **What are the main problems at the existing Nyakitonto market?** Toilets/bathrooms were the most significant problems with 14% of respondents mentioning them. This is followed by clean water (12%), limited security (11%), vehicular accessibility (10%), health & safety (proximity to busy road) garnered 9%,garbage collection (8.5%) parking facilities for lorries (8%), lack of storage (6%), congestion (4.5%), car parking (3%), and load/offload ramp (1%).

Is there an easy built in way within RStudio Rmarkdown knit-to-PDF documents to wrap text to fill available white space either to the right or left of charts?

Regards

解决方案

Here is a work around using latex which might be simple even if it is not elegant. Load the wrapfig package in the yaml header.

Ignore the lipsum package, this is to generate text to demonstrate the wrapping.

Updated with @samcarter_is_at_topanswers.xyz suggestion to use centering and linewidth.

---
title: "wrap text round plot"
output: pdf_document

header-includes:
  - usepackage{wrapfig}
  - usepackage{lipsum}

---

Generate a plot; this does not have to be done in the rmarkdown document as you can source an image directly in the latex code.

```{r plot, include=FALSE}

png("plot1.png")

plot(pressure) 

dev.off()

```    

# Wrap text left


egin{wrapfigure}{r}{0.4	extwidth}
  centering
    includegraphics[width=linewidth]{plot1.png}
  caption{Plot of pressure against temperature}
end{wrapfigure}


lipsum[1-3]


ewpage

# Wrap text right

egin{wrapfigure}{l}{0.5	extwidth}
  centering
    includegraphics[width=0.5	extwidth]{plot1.png}
  caption{Plot of pressure against temperature}
end{wrapfigure}

lipsum[1-3]

这篇关于如何在 Rmarkdown knit-to-pdf 文档中的图表周围环绕文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆