I have a problem with the framed
environment. I am writing a document (article), and several parts of it have a gray background. Unfortunately, when a new page comes, such a shaded environment is cut in half 🙁
How can I avoid this? (with no use of \newpage...
)
Example: In the document generated by this code, I would like the second shaded environment to be placed in the second page:
\documentclass{article}
\usepackage{framed,color}
\definecolor{shadecolor}{gray}{.75}
\begin{document}
\begin{shaded}
Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text
\end{shaded}
\begin{shaded}
Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text\\Text
\end{shaded}
\end{document}
Best Answer
Although it sort of defeats the purpose of the
framed
package, you may enclose everyshaded
environment within aminipage
(of width\linewidth
) to prohibit page breaks. In my example I use theetoolbox
package to patch the defintion of theshaded
environment.