リスト環境を備えた tikz ノード

リスト環境を備えた tikz ノード

私は C++ クラス階層を作成しようとしています。階層内の各ノードは、コード リストを含むクラス記述であり、複数のノードは階層を表す線と矢印で接続されています。tcolorboxコード リストを含むノードを作成し、ボックスを囲んでtikz nodeノード間に線を引けるようにしたいと考えています。

そこでCodeNode環境を作成し、node環境内の関連するものを呼び出そうとしました。MWEはここにあります

\documentclass{book}

\usepackage{tcolorbox}
\usepackage{tikz}
\usepackage{environ}

\tcbuselibrary{listings}


\NewEnviron{CodeNode}{
  \node{%
    \begin{minipage}{0.8\textwidth}
      \begin{tcbwritetemp}
        {\BODY}
      \end{tcbwritetemp}
      \tcbox[arc=0pt,outer arc=0pt,top=1mm,bottom=1mm,left=1mm,right=1mm,
             boxrule=0.6pt,title=#1]{\tcbusetemplisting}
    \end{minipage}
  };
}

\begin{document}

\begin{figure}
  \begin{tcolorbox}
   \begin{tikzpicture}
     \begin{CodeNode}[class name]
       virtual void draw() = 0;
       virtual void some_other_function() = 0;
     \end{CodeNode}
   \end{tikzpicture}
  \end{tcolorbox}
\end{figure}

\end{document}

tcbwritetempでエラーが発生しています

Library (tcolorbox): 'tcblistingscore.code.tex' version '2.60'
)) (./mwe.aux) ABD: EveryShipout initializing macros
! Argument of \next has an extra }.
<inserted text> 
                \par 
l.30      \end{CodeNode}

ここで何が欠けているのでしょうか?

答え1

tikz主な問題は、および との対話における逐語的なテキストのキャプチャにあるようですenviron

私のソリューション提案でenvironは、パッケージをスキップします。これは優れたツールですが、ここでは必要ありません。オプションは、およびCodeNodeによって保存されます。オプションには、ノード名や位置などの必須パラメータを追加しました。私の提供したサンプル設定は、自分のニーズに合わせて簡単に調整できます。mynodeoptionsmytcboptions

\documentclass{book}

\usepackage{tcolorbox}
\usepackage{tikz}

\tcbuselibrary{listings}

\newenvironment{CodeNode}[4][]{
  \tikzset{mynodeoptions/.style={at={(#2)},name=#3,#1}}%
  \tcbset{mytcboptions/.style={title=#4}}%
  \tcboutputlisting%
}{\endtcboutputlisting%
  \node[inner sep=0pt,outer sep=0pt,draw=none,fill=none,mynodeoptions]{%
    \tcbinputlisting{listing only,width=0.8\textwidth,colback=white,
      arc=0pt,outer arc=0pt,top=1mm,bottom=1mm,left=1mm,right=1mm,
      boxrule=0.6pt,mytcboptions}};%
}

\begin{document}

\begin{figure}
\begin{tcolorbox}[center upper,colframe=blue!50!black,colback=blue!5!white]
\begin{tikzpicture}
  \begin{CodeNode}{0,2}{anode}{class name}
virtual void draw() = 0;
virtual void some_other_function() = 0;
  \end{CodeNode}
  \begin{CodeNode}{0,-2}{bnode}{other class name}
virtual void other_draw() = 0;
virtual void yet_some_other_function() = 0;
  \end{CodeNode}
  \draw[red,very thick,->] (anode)--(bnode);
  \draw[red,very thick,->] (anode.east)-- ++(1,0);
  \draw[red,very thick,->] (anode.west)-- ++(-1,0);
\end{tikzpicture}
\end{tcolorbox}
\end{figure}

\end{document}

ここに画像の説明を入力してください

関連情報