Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
Didn't know it was that easy. Would you post as an answer Harish? –  user3232 Feb 23 at 22:24
    
user3232: I have added some shadow for you. See the updated answer. –  Harish Kumar Feb 23 at 23:42

2 Answers 2

up vote 11 down vote accepted

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

share|improve this answer
\documentclass{book}
\usepackage{listings}    
\lstset{frameshape={RYR}{Y}{Y}{RYR}}   
\begin{document}

\begin{lstlisting}[language=Python,breaklines,basicstyle=\footnotesize\ttfamily]{P04-Tk.py}
from tkinter import *                     # import Tkinter module

root = Tk()                               # create Tk root widget

root.mainloop()                           # enter Tkinter event loop
\end{lstlisting}

\end{document}

enter image description here

And for a double line: \lstset{frameshape={ryrRYR}{yY}{yY}{ryrRYR}}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.