该colorframed
包(及其前身framed
)在另一个环境中时会增加额外的垂直空间。
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{colorframed}
\colorlet{shadecolor}{lightgray}
\begin{document}
This is text before quotation, but it must be longer than one line for comparison purposes.
\begin{snugshade*}
Purely fictional thinking leads to testing text inside shaded text environments.
\end{snugshade*}
This is text between quotation, but it must be longer than one line for comparison purposes.
\begin{quotation}\begin{snugshade*}
Purely fictional thinking leads to testing text inside shaded text environments.
\end{snugshade*}\end{quotation}
This is text after quotations, but it must be longer than one line for comparison purposes.
\end{document}
有任何解决这个问题的方法吗?
答案1
我研究了环境colorframed
代码snugshade*
并对其进行了侵入,创建了一个quotedsnugshade*
允许使用可选参数来控制缩进量的环境。
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{colorframed}
\colorlet{shadecolor}{lightgray}
\makeatletter
\newenvironment{quotedsnugshade*}[1][2em]{%
\def\FrameCommand##1{\hskip\@totalleftmargin
\colorframedcolorbox{shadecolor}{##1}%
\hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
\MakeFramed {\advance\hsize-\width
\advance\hsize-2\dimexpr#1\relax %%% ADDED
\@totalleftmargin\dimexpr#1\relax %%% ADDED
\linewidth\hsize
\advance\labelsep\fboxsep
\@setminipage}%
}{\par\unskip\@minipagefalse\endMakeFramed}
\makeatother
\begin{document}
This is text before quotations, but it must be longer than one line for comparison purposes.
\begin{quotedsnugshade*}
Purely fictional thinking leads to testing text inside shaded text environments.
\end{quotedsnugshade*}
This is text after quotations, but it must be longer than one line for comparison purposes.
\begin{quotation}
Purely fictional thinking leads to testing text inside quotation environment.
\end{quotation}
This is text after quotations, but it must be longer than one line for comparison purposes.
\begin{quotedsnugshade*}[2cm]
Purely fictional thinking leads to testing text inside shaded text environments.
\end{quotedsnugshade*}
\noindent\rule{2cm}{1pt}\dotfill margins are 2cm each\dotfill\rule{2cm}{1pt}
\end{document}
请注意,这并未经过测试,因为阴影内容本身就是一个列表。
答案2
使用该tcolorbox
软件包,您可以同时获得彩色背景、分页符和调整边距(如果需要,可以调整上方和下方的空间):
\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\newtcolorbox{quack}[1][]{enhanced,breakable,frame hidden,colback=lightgray,sharp corners,size=small,left skip=1cm,right skip=1cm,#1}
\begin{document}
This is text between quotation, but it must be longer than one line for comparison purposes.
\begin{quack}
Purely fictional thinking leads to testing text inside shaded text environments.
\end{quack}
This is text after quotations, but it must be longer than one line for comparison purposes.
\end{document}