# 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?

• You can supply opacity=0.5 to the tikzpicture options to make everything slightly transparent, and set opacity=1 for those parts of your drawing that you want highlighted.
– Jake
Aug 30, 2012 at 8:18
• To expand on Paul's comment, if you want a more detailed than Jake's given, you will need to show us how you are drawing the diagram at the moment otherwise there could be lots of ways to achieve this but no way for anyone to know which will best help you. Aug 30, 2012 at 8:21

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:

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

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

• @user1362373: Ah, I see! No, this won't work with the preview package if you want to use two separate tikzpictures, because preview puts each tikzpicture into a different page. It works fine with the excellent standalone documentclass, though.