7

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]
  ! \tikz \node[shape=circle,draw](srchead) {H};!
  </ref>
  <ref>//collection[name=Persons]/person[id=4564]
  ! \tikz \node[shape=circle,draw](deshead) {E};
     %(srchead) edge[<->, bend left] (deshead.south); 
  ! 

  </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.

enter image description here

1 Answer 1

7

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]
  !\tikzmark{srchead}{H}!

  </ref>
  <ref>//collection[name=Persons]/person[id=4564]
  !\tikzmark{deshead}{E}! 

   </ref>

  </edge>
  ...
  ...
  ...
  </collection>
\end{lstlisting}
\begin{tikzpicture}[remember picture,overlay]
\path (srchead) edge[<->, bend right] (deshead.south);
\end{tikzpicture}

\end{document}

enter image description here

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

1
  • Wow. I didn't know about tikzmark. It seems very useful indeed. Thanks!
    – Kabira K
    Commented Apr 22, 2013 at 20:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .