Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LaTeX wrapfigure in RMarkdown

I am attempting to use rmarkdown to generate a PDF via LaTeX. I am trying to insert a picture into the PDF, using LaTeX commands withing the RMarkdown document. I am using the LaTeX command wrapfigure which is inserting the figure properly, but then forces text following the current section into a more narrow column, as shown here.

My PDF looks like:

text text text [image]

text text text

text text text

I want:

text text text [image]

text text text text text

text text text text text

The solution to that problem involved using a full LaTeX document, but I am required to use RMarkdown for my class, so that solution will not work for me. How to I get the proper full line formatting that I want, utilizing RMarkdown?

Code Example:

---
title: "Really Awesome Title"
author: "Some Guy"
date: "June 30, 2017"
output:
  pdf_document: default
urlcolor: blue
header-includes:
   - \usepackage{wrapfig}
---

\begin{wrapfigure}{R}{.25\textwidth}
  \begin{center}
    \includegraphics[width=.2\textwidth]{Dave_roberts.png}
  \end{center}
  \caption{Dave Roberts}
\end{wrapfigure}

## Introduction

  Words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words.


### Areas of Interest

  words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words .

### Analytic Technique

  words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words 

### Benefits of Analysis

  words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words 

UPDATE: A friend suggested that I needed to end the section of LaTeX code with a {R}. This made the margin error stop occurring, but it added the text "{R}" to my PDF.

Code now looks like:

\begin{wrapfigure}{R}{.25\textwidth}
  \begin{center}
    \includegraphics[width=.2\textwidth]{Dave_roberts.png}
  \end{center}
  \caption{Dave Roberts}
\end{wrapfigure}{R}

So, it appears to be a problem with ending the LaTeX call. Does anyone have an idea how to end the LaTeX call but not add text to the PDF?

like image 729
Tucktuckgoose Avatar asked Jun 30 '17 11:06

Tucktuckgoose


1 Answers

Your problem comes from the position of your \end{center} argument which should come after the caption. Also wrapfigure will reserve the space arround your figure and make it fit in the available space, so the additional [width=.2\textwidth] is not necessary but that was not creating your problem.

Here is a working example

---
title : "test title"
author: "Some Guy" 
date: "June 30, 2017" 
output:  pdf_document
urlcolor: blue 
header-includes: 
   - \usepackage{wrapfig}
---

```{r echo = FALSE}
url <- "https://cdn.pixabay.com/photo/2017/11/15/20/27/diamonds-2952447_960_720.png"
curl::curl_download(url, "image.png")
``` 

## Introduction

\begin{wrapfigure}{R}{.25\textwidth}  
 \begin{center}
    \includegraphics[width=.2\textwidth]{image.png}  
  \caption{Diamonds} 
\end{center}
\end{wrapfigure}

Words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words.


### Areas of Interest

  words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words .

### Analytic Technique

  words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words 

### Benefits of Analysis

  words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words
words words words words words words words words words words words words words 

Which produces : enter image description here

like image 195
Cedric Avatar answered Nov 07 '22 16:11

Cedric