When using DT::datatable() with Tufte theme and margins, text are not aligned

The following small script generates an example html output using the Tufte theme and marginfigure for text:

---
title: "Example"
date: "`r Sys.Date()`"
output:
  tufte::tufte_html:
    toc: true
    toc_collapsed: true
  tufte::tufte_handout:
    citation_package: natbib
    latex_engine: xelatex
    bibliography: /home/rstudio-myname/dh_d7_d365_RPI/radhoc/dh_d7_d365_RPI/skeleton.bib
link-citations: yes
---

\`\`\`{r setup, include=FALSE}
library(tufte)
library(tidyverse)
# invalidate cache when the tufte version changes
knitr::opts_chunk$set(tidy = FALSE, cache.extra = packageVersion('tufte'))
options(htmltools.dir.version = FALSE)
\`\`\`

# Introduction
\`\`\`
{marginfigure}
This text appears above and right of the datatable whereas was expecting / hoping for it to be aligbned beside it.
\`\`\`

\`\`\`{r ex, echo=FALSE, fig.cap=" ", message=FALSE, warning=FALSE}
mtcars %>% 
  group_by(cyl) %>% 
  summarise(N = n()) %>% 
  DT::datatable(options = list(paging = F, searching = F, info = F), rownames = F)
\`\`\`

\`\`\`{marginfigure}
This text is aligned beside the data. This is what I was hoping for when using DT::datatable
\`\`\`

\`\`\`{r ex2, echo=FALSE, fig.cap=" ", message=FALSE, warning=FALSE}
mtcars %>% 
  group_by(cyl) %>% 
  summarise(N = n()) %>% 
  ggplot(aes(x = N)) +
  geom_bar()
\`\`\`

The result looks like this:

When using ggplot at the bottom, the text appears in the margin as I'd like it to, alongside the image.

However, when using DT::datatable, the text in the marginfigure appears not to the right of the table but to the right AND above.

Is there some way to force the margin figure text to align with the datatable like with the ggplot?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.