« Return to Thread: Using pgf/tikz in verbatim environments like lstlisting

Re: Using pgf/tikz in verbatim environments like lstlisting

by Ludovic Kuty :: Rate this Message:

| View in Thread

And of course, what I've called the "main method" is in fact the "Main class" :) Little nasty typo

Ludovic Kuty

Ludovic Kuty wrote:
For archiving purposes and let people know, I post a simple example I have been working on today to embed graphical objects in lstlisting environments.
As it is the first time I post with Nabble, I hope it won't screw things. Sorry if that's the case.

I have used LaTeXiT for Mac OX X (http://ktd.club.fr/programmation/latexit_en.php) to test the code.

Preamble:

\documentclass[10pt]{article}
\usepackage{color} %used for font color
\usepackage{amssymb} %maths
\usepackage{amsmath} %maths
\usepackage[utf8]{inputenc} %useful to type directly accentuated characters
\usepackage{tikz}
\usetikzlibrary{arrows,automata,shapes}
\tikzstyle{block}=[draw opacity=0.7,line width=1.4cm]
\usepackage{listings}

Document body:

\begin{lstlisting}[basicstyle=\ttfamily,language=Java,escapechar=\%]
%\begin{tikzpicture}[overlay]
\draw[step=.10cm,gray,very thin] (0,-2) grid (8,0);
\draw[step=1cm,gray] (0,-2) grid (8,0);
\node[circle,fill=blue!50,opacity=0.5] (n2) at (3,-0.30) {};
\draw[red] (2.8,-0.1) rectangle (3.8, -0.5);
\draw [->,very thick,red,opacity=.5] (4,-1.7) node [right,text=red, opacity=1] {main method} to [out control=+(180:1)] (3.2, -0.6);
\end{tikzpicture}%
public class Main {
        public static void main(String [] args) {
                System.out.println("Hello world !");
        }
}
\end{lstlisting}

I have added the pdf output here: http://skitch.com/lkuty/t1tw/tikz-in-lstlisting

 « Return to Thread: Using pgf/tikz in verbatim environments like lstlisting