繪製=無和繪製不透明度= 0之間的區別(也適用於填充=無和填充不透明度= 0)?

繪製=無和繪製不透明度= 0之間的區別(也適用於填充=無和填充不透明度= 0)?

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=noneand 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}

在此輸入影像描述

相關內容