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.

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.

share|improve this question
    
Do you have to use listings to create the box? Could you place the listing inside a tikz node? Then you could use something like this: texample.net/tikz/examples/boxes-with-text-and-math –  Jan Hlavacek Jan 15 '11 at 1:04
1  
Well... I don't need. I just didn't know any other way. Maybe you could submit an answer (instead of a comment) containing a sample code? ;) It should work with pdflatex and beamer package. –  Denilson Sá Jan 16 '11 at 20:53
add comment

2 Answers

This is an example using TikZ. Also working with beamer

\documentclass{article}
 \usepackage{tikz}
\usepackage{amsmath}

\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,%
  decorations.pathreplacing,decorations.pathmorphing,shapes,%
  matrix,shapes.symbols,plotmarks,decorations.markings,shadows}

\begin{document}
 \begin{tikzpicture}[x=1cm,y=1cm]
  \node[drop shadow,fill=white,draw,rounded corners] 
   {$\sum\limits_{i=1}^N (x_i-\mu_i)^2$};
 \end{tikzpicture}
\end{document}

Would have posted a picture, but I dont have enough rep. to do so, yet.

Using a listing could look like this:

\documentclass{article}                                                                              
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{listings}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,%
  decorations.pathreplacing,decorations.pathmorphing,shapes,%
  matrix,shapes.symbols,plotmarks,decorations.markings,shadows}

%%%%%%%%%%%%%%%%%%%%%
% Code Listing
%%%%%%%%%%%%%%%%%%%%%
\lstnewenvironment{CODEENV}{
   \lstset{
     language=Matlab,
     numbers=left,
     numberstyle=\tiny,
     stepnumber=1,
     numbersep=1em,
     tabsize=1,
   }
  }{}

%%%%%%%%%%%%%%%%%%%%%
% Document
%%%%%%%%%%%%%%%%%%%%%
\begin{document}
 \begin{tikzpicture}[x=1cm,y=1cm]
  \node[drop shadow,fill=white,draw,rounded corners,inner sep=1em] {
  \begin{CODEENV}
N = 128;
sigma_r = 1;

% Leistungsdichte nach Clark
nu_max      = 1;
nu          = (-nu_max):(2*nu_max/(N-1)):(nu_max);

% Bessel & Clark
xlambda = (0:2/(N-1):2);
rho_R = sigma_r^2*besselj(0, 2*pi*xlambda);

figure;
subplot(211);
plot(xlambda,rho_R/max(rho_R));
subplot(212);
plot(nu, abs(fft(rho_R)).^2);
 \end{CODEENV}
};
 \end{tikzpicture}
\end{document}

Note, that if you have long code snippets, you may need to increase the 'inner sep' parameter of the node, as the line numbering is done outside the listing box (as it seems).

share|improve this answer
1  
The tricky part is not creating the shadow box, but making it work together with listings. –  Juan A. Navarro Jan 24 '11 at 13:51
    
You are right. It was a little tricky –  xeroc Jan 24 '11 at 17:17
add comment

do you mean something like this?

\documentclass{beamer}

\usepackage{listings}

\begin{document}

\begin{frame}[fragile]{demo}
\begin{beamerboxesrounded}[shadow]{A listing}
\begin{lstlisting}
foo
bar
baz 
\end{lstlisting}
\end{beamerboxesrounded}

\end{frame}

\end{document}
share|improve this answer
    
+1 Nice beamer feature –  xeroc Jan 26 '11 at 10:36
add comment

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.