5

This is a R -> latex question. I use tufte_handout

I need to put the caption of a fullwidth table below the table, in the margin, because the table is too wide.

Example of table/caption collision

here is the Rmarkdown file

---
title: "Untitled"
author: "A. Nonymous"
date: "19/8/2017"
header-includes:
   - \usepackage{array}
output:
  tufte::tufte_handout:
    citation_package: natbib
    keep_tex: yes
    latex_engine: xelatex
---

```{r setup, include=FALSE}
library(tidyverse)
library(tibble)
library(knitr)
library(kableExtra)
library(tufte)

knitr::opts_chunk$set(echo = TRUE)

options(knitr.table.format = "latex") 
```


# table


```{r table-1, fig.fullwidth=T, echo=FALSE}

tmp <- tibble(`long titre de texte de colonne` = 1:3, 
              `encore un long titre de colonne` = 101:103,
       `c'est très long là aussi (trop)`=31:33, 
       `mais pourquoi est-ce si long ? (oui, pourquoi?)`=c("a","b","b"))
tmp <- as.data.frame(tmp)

knitr::kable(tmp,booktabs=TRUE,caption="test de test de table, mais c'est trop long et oh là là ça fait une collision") %>% 
  column_spec(1, width = "10em") %>%
  column_spec(2, width = "10em") %>%
  column_spec(3, width = "10em") %>%
  column_spec(4, width = "10em") 

```
Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
user1788720
  • 327
  • 2
  • 11
  • 3
    I don't know enough about those packages to do this, but what you want to do is to modify the generated LaTeX code to use a `table*` environment instead of a `table`, and probably to modify the `\caption` call to shift the caption up or down a bit. Details are in https://github.com/Tufte-LaTeX/tufte-latex/blob/master/sample-book.pdf – user2554330 Aug 25 '17 at 00:55

1 Answers1

1

I know this is not exactly what you are looking for, but I had the same issue and wrapping the table code chunk in ::: {.fullwidth} ::: prevented the overlaping caption (at least). Note that I only added a "" before the chunk "```" for visualisation here.

::: {.fullwidth}
\```{r table-1, fig.fullwidth=T, echo=FALSE}

tmp <- tibble("long titre de texte de colonne" = 1:3, 
              "encore un long titre de colonne" = 101:103,
       "c'est très long là aussi (trop)" = 31:33, 
       "mais pourquoi est-ce si long ? (oui, pourquoi?)" = c("a","b","b"))
tmp <- as.data.frame(tmp)

knitr::kable(tmp,booktabs=TRUE,caption="test de test de table, mais c'est trop long et oh là là ça fait une collision") %>% 
  column_spec(1, width = "10em") %>%
  column_spec(2, width = "10em") %>%
  column_spec(3, width = "10em") %>%
  column_spec(4, width = "10em") 

\```
:::
Ceres
  • 163
  • 7