[Tex/LaTex] get a shadowbox with rounded corners? (using `listings` package)

listingsrounded-cornersshadows

I'm using the listings package as below:

\usepackage{listings}

\lstnewenvironment{pythoncode}[1][]
{\lstset{language=Python,
    basicstyle=\ttfamily\footnotesize,
    frame=shadowbox,
    frameround=tttt,
    rulecolor=\color{black},
    rulesepcolor=\color{gray},
    #1}
}{}

I wanted to get a rounded corners together with a drop-shadow (shadowbox). Is it possible? While the frame border itself had rounded corners, the shadow had square corners, which is kinda ugly.

Best Answer

Next code uses tcolorbox to format the shadowed box where code is inserted through listing package. Size, color and format of shadows can be adapted to ones taste.

\documentclass{article}

\usepackage[most]{tcolorbox}

\newtcblisting{pythoncode}[2][]{%
    enhanced, title=#2, colframe=blue!50!black, 
    colback=blue!10!white, 
    fonttitle=\ttfamily, coltitle=white,
    attach boxed title to top left = {xshift=5mm,yshift=-2mm} ,
    boxed title style={size=small, colback=blue!75!black},
    width=.5\linewidth,
    listing only,listing options={language=Python, basicstyle=\ttfamily\footnotesize},#1}

\begin{document}

\begin{pythoncode}[drop shadow]{hello.py}
#!/usr/bin/env python
def main():
    print "Hello, World!"
if __name__ == '__main__':
    main()
\end{pythoncode}

\begin{pythoncode}[drop fuzzy shadow]{hello.py}
#!/usr/bin/env python
def main():
    print "Hello, World!"
if __name__ == '__main__':
    main()
\end{pythoncode}

\begin{pythoncode}[drop lifted shadow]{hello.py}
#!/usr/bin/env python
def main():
    print "Hello, World!"
if __name__ == '__main__':
    main()
\end{pythoncode}
\end{document}

enter image description here

Related Question