I would like to set off certain parts of my document by giving them a colored background. With the help of adjustbox I was able to write an environment that does more or less what I want: It puts its contents in a borderless, unpadded box with a colored background.
\usepackage{adjustbox}
\newenvironment{shaded}
{\par\noindent\adjustbox{frame=0pt,bgcolor=yellow,minipage=\textwidth}\bgroup}
{\egroup\par}
The problem is that this is, well, a box. It cannot be broken across pages, and it doesn't play nice with floats etc., which cannot be encountered while creating a box. (Thanks to the minipage option, footnotes are captured at the bottom of the shaded area instead of disappearing entirely). For my particular use, restructuring the document to avoid these problems is not an option.
So the question is: Are there any solutions for creating a colored background that are as transparent as possible? I've seen a number of answers for coloring tables, code snippets, boxing that supports page breaks, complete pages(a, b), etc., but nothing I can see how to adapt for more general use.
Complete MWE:
\documentclass{article}
\usepackage{xcolor,adjustbox}
\newenvironment{shaded}
{\par\noindent\adjustbox{frame=0pt,bgcolor=yellow,minipage=\textwidth}\bgroup}
{\egroup\par}
\begin{document}
\section{Regular section}
This section is not highlighted.
This text is just padding to indicate the natural line length.
\begin{shaded}
This is set with a colored background.
\section{Highlighted section}
This entire section is,
actually.\footnote{This footnote is trapped in the minipage.}
\begin{table}
This float triggers an error and disappears.
\end{table}
\end{shaded}
\section{The rest of the document}
\end{document}
mdframedpackage for this. – Claudio Fiandrino Mar 01 '13 at 15:23framedpackage is a different option. – azetina Mar 01 '13 at 15:47framedseems like the way to deal with the page breaks. Unfortunately it's still a box and has the rest of the shortcomings... – alexis Mar 02 '13 at 23:03