4

I'm using the tufte::tufte_handout class in RMarkdown/Rstduio. Is there a way to get a full-width table, as you can a full width image/plot?

EDIT: Just to be clear, I know how make figures full width with the relevant chunk options. Here I want to have the same effect on a table

I'm wondering also whether this is more of a latex question than rmarkdown, so have added that tag.

EDIT2: As a minimal non-working example see:

---
title: "Untitled"
output: tufte::tufte_handout
---

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


```{r, fig.fullwidth = TRUE}
cars %>% t %>% head(20) %>% pander
```
bjw
  • 2,046
  • 18
  • 33

1 Answers1

3

The only way I can think of to get a full-width table working in Tufte Handouts is to use the (awesome) kableExtra package. This package gives you a lot more formatting and editing options and I would recommend looking into these guides here: Guide 1 & Guide 2.

This is the code I got it working with:

---
title: "Tufte Handout"
output:
  tufte::tufte_handout:
    includes:
      in_header: testheader.tex
    latex_engine: xelatex
---

```{r setup, include=FALSE}
library(tufte)
knitr::opts_chunk$set(tidy = FALSE, cache.extra = packageVersion('tufte'), 
kable.force.latex = TRUE)
options(htmltools.dir.version = FALSE)
```

## Full width table

This is a test. This is a test. This is a test. This is a test. This is a 
test. This is a test. This is a test. This is a test.

```{r, resize.width=100, echo=FALSE}
library(knitr)
library(magrittr)
library(kableExtra)
knitr::kable(mtcars[1:6, 1:6], format = "latex", booktabs=T, 
table.envir='table*') %>%
  kable_styling(latex_options = c("hold_position"), full_width=T)
```

Tex header (testheader.tex) for kableExtra:

\usepackage{xcolor}
\usepackage{background}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{array}
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage{float}
\usepackage{colortbl}
\usepackage{pdflscape}
\usepackage{tabu}
\usepackage{threeparttable}

A couple of things are important to get it working which is why I am highlighting it here. Namely: kable.force.latex = TRUE and table.envir='table*'. Obviously you might not need everything that you find in the code and tex header so please feel free to adjust accordingly.

Output looks as follows:

enter image description here

Johnny
  • 751
  • 12
  • 24
  • Thanks, but this just applies to figures, not tables. I think I perhaps wasn't clear enough in my original question so have edited now. – bjw Nov 01 '17 at 07:45
  • Apologies, I should have read your question a bit more thoroughly too. I will amend my answer. – Johnny Nov 01 '17 at 15:33