在 BeforeBeginEnvironment 中向 longfbox 传递参数

在 BeforeBeginEnvironment 中向 longfbox 传递参数

我定义了一个\BeforeBeginEnvironment一个列表并添加了默认\begin{longfbox}[...]定义。我想要的是通过\begin{longfbox}[...]在 中定义了一些自定义参数\BeforeBeginEnvironment。因此,我可以更改背景颜色、边距、填充、边框等...属于 longfbox 周围\begin{lstlisting}...\end{lstlisting}。可能吗?

可能相关:将参数传递给自定义框架选项

最小示例:

\documentclass{beamer}
\usepackage{listings}
\usepackage{longfbox}
\usepackage{verbatim} % to print listing code

% default longbox options
\fboxset{
    rounded,
    border-radius=1ex,
    background-color=blue!50!green!10!white,
    border-color=blue!90!green!50!white,
    margin={10pt,10pt,10pt,10pt},
    padding={10pt,10pt,10pt,10pt}
}

\BeforeBeginEnvironment{lstlisting}{%
% I can define some default parameters here for longfbox
\begin{longfbox}[margin={5pt,5pt,5pt,5pt},%
                 padding={5pt,5pt,5pt,5pt}]%
}
\AfterEndEnvironment{lstlisting}{\end{longfbox}}

\begin{document}
\begin{frame}[fragile]{Example 1}
This is default setup for listing surrounded by longfbox.

\begin{lstlisting}
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  Max.   :25.0   Max.   :120.00
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Example 2}

I want to define arguments for longox after \lstinline!\begin{lstlisting}!
and pass to \lstinline!\longfbox!. is it possible?

\begin{verbatim}
\begin{lstlisting}[background-color=\color{green!10!white},
                   margin={10pt,10pt,10pt,10pt},
                   padding={10pt,10pt,10pt,10pt}]
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  Max.   :25.0   Max.   :120.00
\end{lstlisting}
\end{verbatim}

\end{frame}
\end{document}

相关内容