1

I defined a \BeforeBeginEnvironment for lstlisting and added a default \begin{longfbox}[...] definition. What I want is to pass some custom arguments to \begin{longfbox}[...] defined in \BeforeBeginEnvironment. Hence, I can change background color, margin, padding, border etc... belong to longfbox surrounding \begin{lstlisting}...\end{lstlisting}. Is it possible?

Might be related: Passing arguments to custom frame option

Minimum Example:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.