boshek
boshek

Reputation: 4406

Apply pandoc_args to only part of an rmarkdown doc - eg two columns

Is there a way to create an output with rmarkdown that only has two columns for part of the page? That is I want a header and some text that stretches across a whole page but the figures remain in column formats. Consider the example below where columns are set to 2 but the header remains in there.

Update

I got a bit closer here with the \twocolumn solution but then a new blank page is created.

---
title: "twocol_test"
author: "test"
output: pdf_document
---
  
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## This header should stretch across the whole page
Then this text should also not be in a column. But then the figures below should be organized into two columns:

\twocolumn

```{r}
plot(iris$Sepal.Length, iris$Sepal.Width)
```

```{r}
plot(iris$Sepal.Length, iris$Sepal.Width)
```

\onecolumn


```{r}
plot(iris$Sepal.Length, iris$Sepal.Width)
```

```{r}
plot(iris$Sepal.Length, iris$Sepal.Width)
```

More generally the question is how to apply a pandoc arg to only part of the .Rmd file?

Upvotes: 3

Views: 497

Answers (1)

boshek
boshek

Reputation: 4406

I wasn't exactly able to figure this out but found something that will work for my purposes that involves passing a parameter to the title which spans both columns. Not perfect but this will work:

---
output: 
  pdf_document:
    pandoc_args: [
      "-V", "classoption=twocolumn"
    ]
params:
  test:
    value: test
  set_title: test_title
---

---
title: `r params$set_title`
---

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

```{r}
plot(iris$Sepal.Length, iris$Sepal.Width)
```

```{r}
plot(iris$Sepal.Length, iris$Sepal.Width)
```

```{r}
plot(iris$Sepal.Length, iris$Sepal.Width)
```

```{r}
plot(iris$Sepal.Length, iris$Sepal.Width)
```

Upvotes: 1

Related Questions