以下是最小工作示例:
\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}
我想从节点 H 到 E 绘制一条边。我尝试使用语句 srchead) edge[<->, bend left] (deshead.south);(在代码中注释掉)。提前感谢您的意见。
答案1
不要使用嵌套的 s,而是tikzpicture
建议您采用另一种方法,使用无处不在的变体\tikzmark
;首先放置节点,然后绘制路径:
\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}
现在可以使用选项来获取框架frame=tblr
,并使用来控制宽度linewidth=o.85\textwidth
。