Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question

1 Answer 1

up vote 3 down vote accepted

Although it sort of defeats the purpose of the framed package, you may enclose every shaded environment within a minipage (of width \linewidth) to prohibit page breaks. In my example I use the etoolbox package to patch the defintion of the shaded environment.

\documentclass{article}
\usepackage{framed,color}
\definecolor{shadecolor}{gray}{.75}
\usepackage{etoolbox}
\BeforeBeginEnvironment{shaded}{\begin{minipage}{\linewidth}}
\AfterEndEnvironment{shaded}{\end{minipage}\par}
\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}
share|improve this answer
    
works perfectly! Thank you very much! –  user46317 Jan 6 '13 at 13:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.