【问题标题】:How to wrap text around charts in a Rmarkdown knit-to-pdf document?如何在 Rmarkdown knit-to-pdf 文档中的图表周围环绕文本?
【发布时间】:2021-09-23 03:08:24
【问题描述】:

我有一个 Rmarkdown 文档,它编织成 PDF Text not wrapping around chart

我希望图表右侧的空白区域由文本填充,而不是所有空白区域。我尝试了以下操作,印象是 [h] 限定符将“浮动”图像,文本环绕在图像周围。但是,正如您从链接图像中看到的那样,情况并非如此。

\begin {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%).

在 RStudio Rmarkdown knit-to-PDF 文档中是否有一种简单的内置方式来包装文本以填充图表右侧或左侧的可用空白?

问候

【问题讨论】:

标签: r latex r-markdown pdflatex


【解决方案1】:

这是一个使用乳胶的解决方法,即使它不优雅也可能很简单。在 yaml 头文件中加载wrapfig 包。

忽略lipsum包,这是为了生成文本来演示包装。

更新了@samcarter_is_at_topanswers.xyz 建议使用\centering\linewidth

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

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

---

生成一个情节;这不必在 rmarkdown 文档中完成,因为您可以直接在乳胶代码中获取图像。

```{r plot, include=FALSE}

png("plot1.png")

plot(pressure) 

dev.off()

```    

# Wrap text left


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


\lipsum[1-3]

\newpage

# Wrap text right

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

\lipsum[1-3]

【讨论】:

  • 为了避免额外的垂直间距,我会使用\centering而不是\begin{center}...\end{center}
  • @samcarter_is_at_topanswers.xyz 谢谢你,它节省了一点打字 - 总是一件好事;我已经更新了答案。
  • 不客气! (顺便说一句,答案非常好!)
  • 如果你想节省输入 3 个字符,你可以使用 [width=\linewidth] 代替 [width=0.4\textwidth],线宽会自动适应 wrapfig 的宽度(不会对结果产生任何影响)
  • 间隔可以用width=.9\linewidth 相同的方式改变,但是当然失去了保存字符以输入的优势:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多