
TikZ 鍵值對draw=none
和有什麼差別draw opacity=0
?它們在功能上是否等效,或者在某些情況下應該優先選擇其中一個?同樣,fill=none
和之間有什麼差別fill opacity=0
?
答案1
draw=none
(等於\path
命令)實際上會導致 TikZ 丟棄構造的路徑,並且邊界框不會受到干擾(廢話,它確實改變了邊界框,但只是line width
被忽略了。感謝@Fritz 發現了這個愚蠢的行為)。
draw opacity=0
然而,會導致在沒有墨水的情況下繪製路徑,因此邊界框會使用line width
有效的選項進行更新,因此線條樣式對於邊界框計算很重要。
\begin{tikzpicture}
\draw (0,0) rectangle (3,3);
\draw[opacity=0,line width=1cm] (0,0) rectangle (3,3); % Enlarge the bounding box
\pgfsetlinewidth{5cm} % this has no effect
\pgfpathmoveto{\pgfpointorigin}
\pgfpathlineto{\pgfpoint{4cm}{4cm}} % this updates the known max x,y coordinates!!
\pgfusepath{} % even though it's thrown away.
\begin{pgfinterruptboundingbox}
\pgfpathmoveto{\pgfpointorigin}
\pgfpathlineto{\pgfpoint{10cm}{10cm}} % Nothing happens
\pgfusepath{}
\end{pgfinterruptboundingbox}
\draw[dashed,thin] (current bounding box.north east) rectangle (current bounding box.south west);
\end{tikzpicture}
答案2
filling opacity
不僅適用於填滿操作,也適用於文字和圖像;下面的範例顯示了fill=none
and fill opacity=0
(我實際上fill opacity=0.2
只是為了使文字可見)產生不同結果的情況;fill=none
對節點標籤沒有影響,但fill opacity=<value>
會影響文字:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\fill[olive] (0,0) rectangle (3,2);
\node[fill opacity=0.2] at (3,2) {\huge B};
\node[fill=none] at (0,0) {\huge A};
\end{tikzpicture}
\end{document}