1
votes

I am working towards writing a textbook using R Bookdown, and I want to include pictures in the margins of the text. However, after trying multiple methods none of them seem to actually populate the image in the correct place. I have tried all the options in r bookdown manual and the instructions for using tufte style https://bookdown.org/yihui/rmarkdown/tufte-figures.html.

To make sure I am not having problems with conflicting packages I have been creating a fresh project then pasting the following code into the end of the index.Rmd file.

{r fig-margin, fig.margin=TRUE}
knitr::include_graphics('apple.png')

^![](C:\Users\n298l621\Documents\TESTING\apple.png)

{marginfigure, echo = TRUE}
knitr::include_graphics('apple.png')

The following image is the result of me either knitting the index.Rmd document or building the whole book using the build menu:

results

As you can see, the images are populating but certainly not in the margin. Any help or guidance would be greatly appreciated!

2

2 Answers

0
votes

I do not know how to use r chunk inserting picture in the margin. Here is my document using latex in Rmarkdown insert the compamy logo in left-top margin.

---
documentclass: ctexart
fontsize: 12pt
geometry: a4paper,left=2cm,right=2cm,top=2cm,bottom=3cm
pagesize: a4paper
output:
  rticles::ctex:
    fig_caption: yes
    number_sections: yes
    toc: no
mainfont: 更纱黑体 UI SC #LiberationSerif
sansfont: 更纱黑体 UI SC Xlight #LiberationSans
monofont: 等距更纱黑体 SC Light #LiberationMono
header-includes:
    - \usepackage{fancyhdr}    #load fancyhdr for page header or foot
    - \usepackage{booktabs}
    # - \usepackage{longtable}
    - \usepackage{array}
    - \usepackage{multirow}
    - \usepackage{wrapfig}
    - \usepackage{float}
    - \usepackage{colortbl}
    - \usepackage{pdflscape}
    - \usepackage{tabu}
    - \usepackage{threeparttable}
    - \usepackage{threeparttablex}
    - \usepackage[normalem]{ulem}
    - \usepackage{makecell}
    - \usepackage{xeCJK}
---
\addtolength{\headheight}{1.5cm}
\pagestyle{fancyplain} 
\fancyhead[L]{\includegraphics[height=1.2cm]{cdmlogo.png}} # put the logo at top-left 
\fancyhead[C]{打印日期\today}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0pt}

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r include=FALSE, label='oracle.connection'}
library(tidyverse)
library(ROracle)
library(kableExtra)
0
votes

Could you include an example of the yaml front matter which you are using in your .Rmd?

A document produced with the following code:

---
title: "An MWE of tufte"
author: "chefnate119"
output:
  tufte::tufte_html: default
---

```{r fig-margin, fig.margin=TRUE}
plot(cars)
```

Produces the following document

enter image description here

and to a pdf

---
title: "An MWE of tufte"
author: "chefnate119"
output:
  tufte::tufte_handout: default
---

```{r fig-margin, fig.margin=TRUE}
plot(cars)
```

enter image description here