与 listing 包一起使用时,tikzpicture 的 resizebox 会失败

与 listing 包一起使用时,tikzpicture 的 resizebox 会失败

这是失败的示例

\documentclass{standalone}
\usepackage{tikz}
\usepackage{float}
\usepackage{listings}
\usepackage{color}
\usepackage{textcomp}
\usetikzlibrary{shapes,positioning}
\begin{document}
\centering
\resizebox{5.00in}{!}{
\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}

答案1

listings是逐字类环境,您永远不能在命令的参数中使用此类环境。lrbox引入此环境的目的正是:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{float}
\usepackage{listings}
\usepackage{color}
\usepackage{textcomp}
\usetikzlibrary{shapes,positioning}
\begin{document}
\centering
\begin{lrbox}{0}%
\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{lrbox}
\resizebox{5.00in}{!}{\usebox0}
\end{document}

相关内容