如何避免框架/阴影的断裂?

如何避免框架/阴影的断裂?

我的环境有问题framed。我正在写一篇文档(文章),其中有几部分的背景是灰色的。不幸的是,当新一页出现时,这样的阴影环境就被切成两半 :(

我该如何避免这种情况?(不使用\newpage...

示例:在此代码生成的文档中,我希望将第二个阴影环境放置在第二页:

\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}

答案1

虽然这有点违背了framed包的目的,但你可以将每个shaded环境括在minipage(宽度为\linewidth)内,以禁止分页。在我的例子中,我使用了etoolbox包来修补环境的定义shaded

\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}

相关内容