Highlighting part of TikZ figure

I'm looking for a way to use transparency/opacity to highlight a particular area in a TikZ figure I generated. To be more specific, I have a TikZ figure that illustrates the relationship between several concepts. After I have shown this figure for the first time, I want to reuse it later in my document when I discuss specific concepts in more detail. To make clear which concept of the figure is discussed, I want to highlight the relevant part of the figure. It would be nice if there was a way in which I could leave the relevant part of the figure unchanged and make the rest of the figure somewhat faded using opacity. Is there a simple way to do this?

Update: Here's an MWE:

\documentclass[10pt]{article}  \usepackage{tikz} \usepackage{fancyhdr} \usepackage[active,tightpage]{preview} \PreviewEnvironment{tikzpicture}  \begin{document}  \thispagestyle{empty}  \begin{tikzpicture}[   opacity=0.5,   box/.style={rectangle,draw=black,     minimum size=1cm,text width=2.2cm,text centered,font=\small}]  %%% coordinates   \coordinate (CM) at ( 0.0, 3.0);   \coordinate (DM) at ( 0.0, 6.0);   \coordinate (MM) at ( 0.0, 9.0);   \coordinate (PR) at ( 0.0,12.0);  %%% nodes     \node[box] (cm) at (CM) {box 1};   \node[box] (dm) at (DM) {box 2};   \node[box] (mm) at (MM) {box 3};      \node[box] (pr) at (PR) {box 4};   %%% arrows   \draw[->] (dm.south) --      node[fill=white,align=center,text width=3.5cm,font=\small]      {\textsl{proc 1}} (cm.north);      \begin{scope}[opacity=1.0]     \draw[->] (mm.south) --        node[fill=white,align=center,text width=3.3cm,font=\small]        {\textsl{proc 2}} (dm.north);   \end{scope}    \draw[->] (pr.south) --      node[fill=white,align=center,text width=3.5cm,font=\small]      {\textsl{proc 3}} (mm.north); \end{tikzpicture}  \end{document} 

This does not quite do what I want because: (1) I would like to be able to specify a circle or rectangle that contain the highlighted portion of the figure, rather than having to explicitly select which commands should not be in the background. (2) Ideally, I would like to not have to modify the basic source for the figure so I can keep it in a separate file and simply input it and add the command to select the portion to be highlighted. (3) The text superimposed on the arrows works fine because of the white background when there is no opacity. But with opacity, the white background no longer covers the arrow. Is there an easier solution rather than drawing the arrows in two pieces?

Replay

You can draw a semi-transparent mask on top of your existing tikzpicture by using remember picture to make the coordinates available. The pictures show the mask in red for demonstration, and in white for the actual application:

Highlighting part of TikZ figure
Highlighting part of TikZ figure

\documentclass[10pt]{article}

\usepackage{tikz}
\usepackage{fancyhdr}

\begin{document}

\thispagestyle{empty}

\begin{tikzpicture}[remember picture,
  box/.style={rectangle,draw=black,
    minimum size=1cm,text width=2.2cm,text centered,font=\small}]

%%% coordinates
  \coordinate (CM) at ( 0.0, 3.0);
  \coordinate (DM) at ( 0.0, 6.0);
  \coordinate (MM) at ( 0.0, 9.0);
  \coordinate (PR) at ( 0.0,12.0);

%%% nodes
  \node[box] (cm) at (CM) {box 1};
  \node[box] (dm) at (DM) {box 2};
  \node[box] (mm) at (MM) {box 3};
  \node[box] (pr) at (PR) {box 4}; 

%%% arrows
  \draw[->] (dm.south) --
    node[fill=white,align=center,text width=3.5cm,font=\small] (proc1)
    {\textsl{proc 1}} (cm.north);  

    \draw[->] (mm.south) --
      node[fill=white,align=center,text width=3.3cm,font=\small]
      {\textsl{proc 2}} (dm.north);

  \draw[->] (pr.south) --
    node[fill=white,align=center,text width=3.5cm,font=\small]
    {\textsl{proc 3}} (mm.north);
    \coordinate (diagramNW) at (current bounding box.north west);
    \coordinate (diagramSE) at (current bounding box.south east);
\end{tikzpicture}

%% The mask
\begin{tikzpicture}[remember picture, overlay]
\fill [red, opacity=0.5,even odd rule]
    (diagramNW) rectangle (diagramSE) % Cover up everything
    (mm.north west) rectangle (dm.south east) % Cut out a rectangular area;
    (proc1) circle [radius=0.5cm];
\end{tikzpicture}

\end{document}

Category: tikz pgf Time: 2012-08-30 Views: 0
Tags: tikz pgf

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.215 (s). 12 q(s)