答案1
你不varwidth
如果您的目的是让灰色框覆盖整个列宽,则想要使用。
其目的varwidth
是使封闭盒足够宽,以容纳里面的材料。
\documentclass{article}
\usepackage{xcolor,multicol}
\usepackage{lipsum}
\definecolor{light-gray}{gray}{.85}
\newsavebox{\songboxbox}
\newenvironment{songbox}
{\begin{lrbox}{\songboxbox}\begin{minipage}{\dimexpr\columnwidth-2\fboxsep}\itshape}
{\end{minipage}\end{lrbox}%
\par\medskip\noindent
\colorbox{light-gray}{\usebox{\songboxbox}}%
\par\medskip}
\begin{document}
\begin{multicols}{2}
Some text some text some text some text
some text some text some text some text
some text some text some text some text
\begin{songbox}
In this long line the box goes all the way
to the right margin. And it wraps nicely.
\end{songbox}
Some text some text some text some text
some text some text some text some text
some text some text some text some text
\begin{songbox}
This line ends here.
Another line.
\end{songbox}
Now we fill the columns. \lipsum[1-10]
\end{multicols}
\end{document}
在我看来,环境形式似乎更好。