# tikz inside lstlisting inside tikz

Here is the minimum working example:

\documentclass{article}
\usepackage{tikz}
\usepackage{float}
\usepackage{listings}
\usepackage{color}
\usepackage{textcomp}
\usetikzlibrary{shapes,positioning}
\begin{document}
\centering
\begin{tikzpicture}
\node[draw] (PersonLocation Graph) {
\begin{minipage}{.85\linewidth}
\begin{lstlisting}[language=XML,escapechar=!]
<collection name=PersonLocation BiMap>
<edge>
<ref>//collection[name=Locations]/loc[name=XXYY]
</ref>
<ref>//collection[name=Persons]/person[id=4564]
!

</ref>

</edge>
...
...
...
</collection>
\end{lstlisting}
\end{minipage}

};
\end{tikzpicture}
\end{document}


I want to draw an edge from node H to E. I tried using statement srchead) edge[<->, bend left] (deshead.south); (commented out in the code). Thanks in advance for your input.

Instead of using nested tikzpictures, I would suggest you another approach using a variant of the ubiquitous \tikzmark; first you place the nodes, and then you draw the path:

\documentclass{article}
\usepackage{tikz}
\usepackage{float}
\usepackage{listings}
\usepackage{color}
\usepackage{textcomp}
\usetikzlibrary{shapes,positioning}

\newcommand\tikzmark[2]{%
\tikz[remember picture,overlay]\node[circle,draw] (#1) {#2};}

\begin{document}

\begin{lstlisting}[
language=XML,
escapechar=!,
linewidth=.85\textwidth,
frame=tblr
]
<collection name=PersonLocation BiMap>
<edge>
<ref>//collection[name=Locations]/loc[name=XXYY]

</ref>
<ref>//collection[name=Persons]/person[id=4564]

</ref>

</edge>
...
...
...
</collection>
\end{lstlisting}
\begin{tikzpicture}[remember picture,overlay]
\end{tikzpicture}

\end{document}


The frame is now obtained with the option frame=tblr, and the width is controlled with linewidth=o.85\textwidth.

• Wow. I didn't know about tikzmark. It seems very useful indeed. Thanks! – Sandeep Apr 22 '13 at 20:53