[Tex/LaTex] Rounded corner for the code listing

listingsrounded-corners

Is it possible to make a rounded corner for the tex code listing? Given:

\documentclass[10pt]{article}
\usepackage[usenames,dvipsnames]{xcolor} %used for font color
\usepackage[utf8]{inputenc} %useful to type directly diacritic characters
\usepackage{listings}
\usepackage{tcolorbox}
\tcbuselibrary{listings}

\begin{document}

\definecolor{lbcolor}{rgb}{0.1,0.1,0.1}

\lstdefinestyle{mystyle}{
     basicstyle=\ttfamily\color{White},
     language=Java,
     tabsize=1,
     keywordstyle=\color{Red}\bf,
     showstringspaces=false,
     morekeywords={public, class}
 }

\newtcblisting{mylisting}{
      arc=0pt,
      top=0mm,
      bottom=0mm,
      left=0mm,
      right=0mm,
      boxrule=0pt,
      colback=black,
      listing only,
      listing options={style=mystyle},
      hbox
}

\begin{mylisting}
public class MyObject{

    public MyObject(){
        System.out.println("MyObject");
    }
}
\end{mylisting}

\end{document} 

I would like to make a rounded corner. This code will be included in a presentation, and although only a cosmetics issue, it looks much appealing when you have nice rounded corners and shadows. Is it possible to do in in Latex?

Best Answer

The option arc is provided for this purpose. You have set it to 0pt. Change its value to say some thing like 5mm (say). Further, you can add shadows with enhanced option and skins library of tcolorbox. The syntax would be

shadow={<xshift>}{<yshift>}{<offset>}{<options>}

Full code:

\documentclass[10pt]{article}
\usepackage[usenames,dvipsnames]{xcolor} %used for font color
\usepackage[utf8]{inputenc} %useful to type directly diacritic characters
\usepackage{listings}
\usepackage{tcolorbox}
\tcbuselibrary{listings,skins}        %%% skins needed for shadow

\begin{document}

\definecolor{lbcolor}{rgb}{0.1,0.1,0.1}

\lstdefinestyle{mystyle}{
     basicstyle=\ttfamily\color{White},
     language=Java,
     tabsize=1,
     keywordstyle=\color{Red}\bf,
     showstringspaces=false,
     morekeywords={public, class}
 }

\newtcblisting{mylisting}{
      enhanced,                             %%% needed for shadow
      arc=5mm,
      top=0mm,
      bottom=0mm,
      left=0mm,
      right=0mm,
      boxrule=0pt,
      colback=black,
      shadow={5mm}{-3mm}{0mm}{fill=black!50!white,
                      opacity=0.5},             %%% here for shadow  and adjust as you like
      listing only,
      listing options={style=mystyle},
      hbox
}

\begin{mylisting}
public class MyObject{

    public MyObject(){
        System.out.println("MyObject");
    }
}
\end{mylisting}

\end{document}

enter image description here

Related Question