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.

I have something drawn as a tikzpicture:

\begin{tikzpicture}
  \node[above] at (8,13) {$...$};
  \filldraw[fill=white!20] (2,0) rectangle (6,12);
  \draw (2,4) -- (2,12); \draw (2,12) -- (6,12); \draw (6,12) -- (6,4);
  \draw [dashed] (6,3) -- (1,3);
  ...
\end{tikzpicture}

Now I would like to draw a non-transparent white rectangle which hides a part of the picture, so that what is under the rectangle becomes invisible or less visible (e.g. gray). Does anyone know how to do it?

share|improve this question
    
\draw (2,4) -- (2,12); ... is not useful after \filldraw ... –  Alain Matthes Aug 15 '12 at 16:11
add comment

1 Answer

up vote 7 down vote accepted

You can simply move the \filldraw command to be after what you want hidden, and control the opacity with fill opacity=<opacity>:

enter image description here

If you want what is underneath to be complely hidden, adding fill opacity=1.0 captures the specific intent (even though it is the default).

Note:

  • I changed the color to yellow!20 to make the effect clearer in the image here. Replacing this with fill=white will give you the desired result.

Code:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\foreach \OpacitySetting in {1.0, 0.95, 0.75}{%
\begin{tikzpicture}
\draw [blue, ultra thick] (0,2) -- (4,2);
\filldraw[fill=yellow!20, fill opacity=\OpacitySetting] (1,0) rectangle (3,4) 
    node [above left, text opacity=1.0]  {opacity=\OpacitySetting};
\end{tikzpicture}%
\hspace{0.25cm}%
}%
\end{document}
share|improve this answer
    
Thank you... How can I do not show the edges of the rectangle? –  SoftTimur Aug 15 '12 at 16:49
1  
@SoftTimur \draw draws just the edge of the rectangle, \fill just fills the rectangle without drawing the edge, while \filldraw does both. In other words, replace \filldraw with \fill. –  Torbjørn T. Aug 15 '12 at 16:57
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.