Defining a centered shadowboxed listings environment
Here is a proposal using tcolorbox
. Colors, shadows, etc. can be adjusted to your liking. You may replace style=tcblatex
by any listings setting you want to have as default for your environment.
\documentclass[twocolumn]{article}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\newenvironment{CenteredShadowboxListing}[1][]{%
\tcbset{listing options={style=tcblatex,#1}}\tcbwritetemp}%
{\endtcbwritetemp%
\tcbox[enhanced,arc=0pt,outer arc=0pt,top=1mm,bottom=1mm,left=1mm,right=1mm,
boxrule=0.6pt,drop fuzzy shadow,before=\begin{center},after=\end{center}]%
{\tcbusetemplisting}}
\begin{document}
\lipsum[4]
\begin{CenteredShadowboxListing}
line of code
line of code
\end{CenteredShadowboxListing}
\lipsum[4]
\end{document}
UPDATE: With tcolorbox
version 2.41
of 2013/07/23
, the code to typset the example above can be written more compact with the same result:
\documentclass[twocolumn]{article}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}% version 2.41 or newer
\newtcblisting{CenteredShadowboxListing}[1][]{%
listing options={style=tcblatex,#1},hbox,listing only,
enhanced,arc=0pt,outer arc=0pt,top=1mm,bottom=1mm,left=1mm,right=1mm,
boxrule=0.6pt,drop fuzzy shadow,before=\begin{center},after=\end{center}}
\begin{document}
\lipsum[4]
\begin{CenteredShadowboxListing}
line of code
line of code
\end{CenteredShadowboxListing}
\lipsum[4]
\end{document}