
各エッジに特定の重みがあり、線の幅とエッジのラベルの両方で視覚化されたツリーを描画したいと思います。TikZ を使用すると、これは非常に簡単です。
\documentclass{standalone}
\usepackage{tikz-qtree}
\begin{document}
\begin{tikzpicture}[
clabel/.style = { fill=white, circle, inner sep=1pt,font=\scriptsize},
]
\Tree [.O
\edge [line width = 2] node [clabel] {2}; L
\edge [line width = 4] node [clabel] {4}; R
]
\end{tikzpicture}
\end{document}
描きたい木はかなり大きいので、エッジコードを分離したい。つまり、次のようなマクロが欲しい。
\def\edgeweight#1{\edge [line width = #1] node [clabel] {#1}; }
\edge
残念ながら、このマクロを呼び出すと、LaTeX はコマンドについてエラーを出します。これは、マクロが\Tree
コマンドの外側に出現するためだと思われます。これを修正する方法はありますか?
答え1
次のコードをプリアンブルに追加すると、問題は解決します。
\makeatletter
\let\old@@children\@@children
\def\@@children{\futurelet\my@next\my@@children}
\def\my@@children{%
\ifx\my@next\edgeweight\else
\expandafter\@gobble
\fi
\expandafter\old@@children}
\makeatother
この解決策はDavid Carlisleによるもので、ここ関連する質問検出器を書いた人、おめでとうございます。これで正しい場所にすぐにたどり着けました!