我正在尝试创建一个引用环境,将引用放在灰色背景上,并在其上方放置一条彩色规则:
\documentclass{memoir}
\usepackage{color}
\usepackage[papersize={100mm,100mm},noheadfoot,margin=25mm]{geometry}
\pagestyle{empty}
\definecolor{shadecolor}{gray}{0.7}
\newdimen\X\X=22pt\advance\X3\baselineskip
\newenvironment{Quote}%
{\parindent0pt\parskip1\baselineskip%
\par%
\textcolor{red}{\rule{\hsize}{6pt}}\\[-\X]%
\nopagebreak%
\begin{quote}\noindent\leftmargin0pt\rightmargin0pt\begin{qshade}%
}%
{\end{qshade}\end{quote}}
\begin{document}
\begin{Quote}A small quote\end{Quote}
\begin{Quote}A small quote\end{Quote}
%\begin{Quote}A small quote\end{Quote}
\end{document}
这样做没问题,但是当我取消注释第三个引文时,即使有 \nopagebreak,规则和引文之间也会出现分页符。此外,这会在规则和其他两个引文的阴影框之间引入额外的白色。我该如何防止这种情况发生?
答案1
mdframed
我建议你为此雇用:
\documentclass{memoir}
\usepackage{color}
\usepackage[papersize={100mm,100mm},noheadfoot,margin=25mm]{geometry}
\pagestyle{empty}
\usepackage{mdframed}
\definecolor{shadecolor}{gray}{0.7}
\newenvironment{Quote}
{\par\parindent0pt\parskip1\baselineskip
\begin{mdframed}[linecolor=red,
linewidth=6pt,
backgroundcolor=shadecolor,
bottomline=false,leftline=false,rightline=false]
}
{\end{mdframed}}
\begin{document}
\begin{Quote}A small quote\end{Quote}
\end{document}
这不会在顶部的红色规则和引用之间造成任何中断。