網路城邦
上一篇 回創作列表 下一篇   字體:
TiKz 的label 與 pin
2015/04/21 10:05:37瀏覽967|回應0|推薦2

前文有提到座標或是節點的label指令的用法,其實還有一個用來標示的功能是pin。

在TiKz的文件中,有一節是專門討論這二者的用法。

label=[options] angle:text,如

\coodinate[label=A] (a) at (1,2) ;

label 的 options 通常用在node上面。而 angle 則是要標示的位置是在點的那個方位。如上方:

label=above:A或 label=90:A 

absolute 則用以node的平均座標位置來標示:

\draw[help lines] (0,0) grid (5,5);

\node at (1,3) [rotate=-80, draw][label={[red,draw]right:label}]{main node};

\node at (3,3) [rotate=-80, draw][label={[red,draw, absolute]right:label}]{main node};

label distance=長度,則是設定label 的距離:

\node at (1,1) [fill=blue!50,circle,inner sep=0.5 cm][label={[text=red]above:A}] [label={[text=brown,label distance=1cm]right:B}][pin={[pin distance=1.5cm, pin edge={thick}, inner sep=1pt]40:C}]{};

如下圖的A和設定距1cm的B。

pin的用法和label幾乎一樣:

pin=[options] angle: text

差別是多出一條直線連向node。參數一樣有 pin distance,不過它多出一條線的關係,所以多了一個pin edge,可以對這條連線做各種的設定。如上例C。

其實二者都是node的一種,所以node的相關參數都能使用。

下面一例是畫出一個恒星,行星,衛星的示意圖,因用到坐標的運算,所以需要使用calc library,使用pin指令來說明:

\usetikzlibrary{calc}

\node[inner color=white, outer color=orange, inner sep=0.5cm,circle, pin={[pin distance=4cm, pin edge=red, text=blue]130: Star}] at (2.5,2.5) {};

\draw[line width=2pt, draw=gray!80] (5,2.5) arc [start angle=0, end angle=360, x radius=2.5cm, y radius=2cm]node [name=earth, pos=0.6,ball color=blue!70,shading angle=-100, circle, pin={[pin distance=2cm,text=blue,pin edge=red, name=pinearth]left: Planet}]{};

\draw($(earth)+(0.5,0)$) arc [start angle =0, end angle=360, x radius=0.5cm, y radius=0.3cm, dotted] node [circle,ball color=gray, shading angle=-120,inner sep=0.5mm,pos=0.2, name=moon, pin={[pin distance=3cm,text=blue, pin edge=red ]120: Satellite}]{};

上例的name 是一個node的操作指令,是指定一個名稱來代表該node的位置。如果指定sun在(3,3),可以這樣做:
\node (sun) at (3,3) {};
或是
\node at (3,3)[name=sun]{};
在這個node的坐標需要其他的運算時,用(sun)來代表這個node位置來做運算。name是個常用的指令,可以用在許多物件上面,如node, child node, label node, pin node等等。
( )
回應 推薦文章 列印 加入我的文摘
上一篇 回創作列表 下一篇

引用
引用網址:https://classic-blog.udn.com/article/trackback.jsp?uid=paraquat&aid=22385144