Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

What is the difference between the TikZ key-value pairs draw=none and draw opacity=0? Are they functionally equivalent, or are there situations in which one should be preferred over another? Similarly, what is the difference between fill=none and fill opacity=0?

share|improve this question
    
I once had a case where I wanted to print 2 versions of a document: with and without labels. The first thing I did was text opacity=0. Although nothing was visible in the PDF file, fractions of the labels appeared in the printed version, so be careful ;) –  Tom Bombadil Aug 18 '12 at 17:54
add comment

2 Answers 2

up vote 12 down vote accepted

draw=none (which is equal to \path command) actually causes TikZ to throw away the constructed path and the bounding box is not disturbed (Nonsense, it does change the bounding box but only line width is ignored. Thanks to @Fritz for catching this stupidity).

draw opacity=0 however causes the path to be drawn with no ink so the bounding box gets updated with line width option in effect, so the line style matters for the bounding box calculation.

\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}

enter image description here

share|improve this answer
    
@GonzaloMedina Both answers are great -- just what I was looking for. I decided to accept @percusse's answer only because I was originally slightly more interested in draw; I wish I could accept both answers. –  Henry DeYoung Aug 18 '12 at 20:00
    
The beginning of this answer "draw=none [...] causes TikZ to throw away the constructed path and the bounding box is not disturbed" is a bit misleading. The bounding box is indeed disturbed, if the path itself (not the line width) protrudes from the bounding box. In your example \path[line width=4cm] (0,0) rectangle (3,6); would actually modify the bounding box, despite it not drawing. Thus the only difference between draw=none and draw opacity=0 is that the line width has no effect with the former. For "hypothetical curves" you would use the pgfinterruptboundingbox environment. –  Fritz Aug 22 '12 at 21:23
    
@Fritz It's not misleading, it's flat out wrong :) Apparently, I didn't do enough experiments and jumped to conclusions. Thanks for the catch. I'll update it as soon as possible. –  percusse Aug 22 '12 at 21:33
add comment

filling opacity applies not only to filling operations, but also to also applies to text and images; the following example shows a case in which fill=none and fill opacity=0 (I actually used fill opacity=0.2 just to make the text visible) produce different results; fill=none has no effect on the node label, but fill opacity=<value> will affect the text:

\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}

enter image description here

share|improve this answer
    
Thanks! It seems like a strange design choice to have fill opacity also affect the text opacity; why not leave that altogether to text opacity? –  Henry DeYoung Aug 18 '12 at 17:22
    
@HenryDeYoung no; they are not completely equivalent; I was composing some examples, but percusse has answered this part now. –  Gonzalo Medina Aug 18 '12 at 17:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.