1

It's a known issue of tufte-* that \sidenote and \marginnote won't build if used inside mdframed environments or tcolorboxes. I'm not finding a workaround for that, and most posts on the topic suggest there isn't one.

What I want is simply to put a nice gray background behind some paragraphs in a tufte-handout. Can this be done without mdframed or tcolorbox?

EDIT: Minimal example

\documentclass[nobib,justified]{tufte-handout}

\usepackage{mdframed}

\newmdenv[
  linecolor=lightgray,
  linewidth=3pt,
  leftmargin=0pt,
  innerleftmargin=0pt,
  rightmargin=0pt,
  innerrightmargin=0pt
]{graybox}

\usepackage{lipsum}

\begin{document}

\begin{graybox}
\lipsum[1]
\marginnote{This is a marginnote}
\end{graybox}

\end{document}

Fails to build with ! LaTeX Error: Float(s) lost.

5
  • 1
    Could you add a runable, minimal example code whichs shows the problem?
    – cis
    Commented Sep 10, 2020 at 17:56
  • It can be done with the shaded environment (from Donald Arseneau's ` framed` package), which can break across pages.
    – Bernard
    Commented Sep 10, 2020 at 19:21
  • @Bernard: are you sure? I just tested and the side note doesn't show up. Commented Sep 10, 2020 at 19:44
  • Side notes are in the margin? Shaded, unless you patch it , shades only the text area width. Could you post a small code reproducing your problem?
    – Bernard
    Commented Sep 10, 2020 at 20:52
  • See here for "tufte": tex.stackexchange.com/a/366097/46023
    – cis
    Commented Sep 11, 2020 at 17:54

1 Answer 1

2

Here's a bit of a stupid hack that may have a lot of bugs, but it seems to work for short paragraphs away from page breaks.

\documentclass{tufte-handout}
\usepackage{tcolorbox}
\usepackage{blindtext}

\usepackage{environ}

\makeatletter
\NewEnviron{grayground}{%
    \noindent\smash{\begin{tcolorbox}[colback=gray!20, colframe=gray!20, oversize, top=0pt, bottom=0pt, left=4pt, right=4pt, box align=top]
    \let\sidenote\@gobble
    \let\marginnote\@gobble
    \color{gray!20}\BODY
    \end{tcolorbox}}\par\BODY}
\makeatother

\begin{document}

\begin{grayground}
\blindtext\sidenote{\blindtext}\blindtext
\end{grayground}

\end{document}

Explanation

The basic idea is to first print the text once using tcolorbox, but suppress any sidenote or marginnote, with the text the same color as the background to hide it.

Then we print the real text, with active sidenote and margin note on top of it.

Now, I am counting on the measurement of the version with the sidenote superscripts and the version without to be very similar, so while the two texts are not exactly the same they should take up roughly the same amount of vertical space and so you can get away with this.

To implement this, you can just use a tcolorbox to do the first round of printing. Then you smash it.

Inside the tcolorbox you can let marginnote and sidenote to @gobble to suppress their function. You finish by printing the same text again.

To make it easier to use you can wrap everything inside an Environ.

The output looks something like this (image is slightly out-of-date; I made some adjustments in the code to make the fit a bit better).

enter image description here

3
  • Wow, that's some hackery! Commented Sep 10, 2020 at 20:32
  • Not robust enough for production unfortunately. The page break behavior is quite erratic. Commented Sep 11, 2020 at 13:18
  • yeah.. that's just an idea. Page breaks will be hard to handle in general. Commented Sep 11, 2020 at 14:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .