TikZのnode
from TikZ
TikZのnode
テキストボックスのようなものと考えていい
\nodeを使う
\path nodeと等価
\pathの途中の任意の位置に入れる
$ node (:name) at (:coordinate) {:node_contents};
at (:coordinate)と(:name)は順不同
at (:coordinate)を省略すると、最後に\path命令が利用した座標に設定される
初期状態だと原点$ (0,0)
\pathの途中に入れたときは、その時の座標が使われる
例
code:node.tikz(tex)
\begin{document}
\begin{tikzpicture}
\node {O};
\draw (1,1) node {A} rectangle node {Label} (2,2) node {B} ;
\end{tikzpicture}
\end{document}
node {O}は直前になんの命令も無いので、原点に配置される
node {A}は$ (1,1)の直後に記述されているので、$ (1,1)に設定される
node {Label}はrectangle命令の直後なので、rectangleが指定する座標である長方形の中央に設定される
この場合だと$ (1.5,1.5)かな
code:node2.tikz(tex)
\begin{document}
\begin{tikzpicture}
\draw (1,1) node at (1,1.5) {A} node {B} rectangle (2,2) node {C} node {D} ;
\end{tikzpicture}
\end{document}
at (:coordinate)で座標を上書きできる
効果は当該nodeにしか発生しない
$ Aは上書きした座標に表示されているが、$ Bには元々の座標$ (0,0)が適用されている
それぞれoptionに書き換えられる
code:node3.tikz(tex)
\begin{document}
\begin{tikzpicture}
\nodedraw (A) at (1,1) {A};
\nodedraw,name=B at (2,1) {B};
\nodedraw,at={(3,1)} (C) {C};
\nodedraw,name=D,at={(4,1)} {D};
%\nodedraw,at={(5,1)},node contents=E (E); % 不可
\nodedraw,name=E,at={(6,1)} at (5,1) {E}; % optionでないほうの座標が優先される
%\nodedraw,name=F, node contents=F, at={(6,1)} at (5,1); % 不可
%\nodedraw,name=D, node contents=D at (4, 1); % 不可
\nodedraw,name=F, node contents=F, at={(6,1)};
\end{tikzpicture}
\end{document}
shape=:shape_nameoptionでNodeの形を決める
defaultはrectangle
shape=は省略可
rectangle,circle,coordinateのどれかを入れる
code:node-shape.tikz(tex)
\begin{document}
\begin{tikzpicture}
\nodedraw at (1,1) {A};
\nodedraw,rectangle at (2,1) {B};
\nodedraw,circle at (3,1) {C};
\nodedraw,coordinate at (4,1) {D};
\end{tikzpicture}
\end{document}
coordinateは大きさが0でnode contentsが空のnode
普通は\coordinateで記述する
大きさはinner sepとouter sepで変えるhttps://tikz.dev/tikz-shapes#sec-17.2.2
ラベル(=node contents)をつける
パス中にノードを配置する | TikZ — Tasuku Soma's webpage
ラベルを付けたい対象の次にnode[:position]{:label}をつける
座標(A)のほか、線--などにもつけられる
label=:labeloptionでラベルを作れる
node contentsとは別。つまり両方設定できる
quotes (TikZ)を入れると":label"と略記できるようになる
Nodeと線で結ばれたラベルを作る
$ \nodepin=:label at (:coord) {};
これもnode contentsとは別
code:node-path.tikz(tex)
\begin{document}
\begin{tikzpicture}
\nodedraw (A) at (0,0) {A};
\nodedraw (B) at (1.5,1.5) {B};
\draw (A) to bend right node {text} (B);
\end{tikzpicture}
\end{document}
#2024-12-19 13:33:29
#2024-06-03 23:35:54
#2024-03-13 19:01:06
#2024-01-22 19:01:11