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

  • TikZ figure in parts-environment 2014-04-30

    I'd like to have a TikZ figure in a parts-environment, but the figure appears above part (a) instead of below. How can I get the picture to follow the (a)? Thanks for your help! \documentclass[addpoints,12pt]{exam} \usepackage[utf8]{inputenc} \usepac

  • Fitting page size to a tikz figure 2011-07-20

    Sometimes I'm using tikz as a plotting tool, without embedding the figure in a document. In this case, I normally, want to include the resulting PDF in a different TeX file (yes I know I could include the TikZ code directly, but it is not helpful in

  • Scaling and positioning TikZ figures in equation environments 2012-01-31

    I am trying to use TikZ figures as part of an equation, but I am only able make either the positioning or the scaling appear correctly. For instance, giving my figures the correct size using "resizebox" makes them appear as follows (enlarged for

  • Highlighting part of an image 2012-10-19

    I want to highlight part of an image in beamer by drawing a box around it and setting the rest of the image to a dim setting. I do not know how to decrease the brightness of the rest of the picture. Below is my partial attempt, which almost does the

  • Putting shade in part of a figure in `picture` environment 2013-07-20

    I was trying to draw the some diagram by using the picture environment. I want to put shade certain part of the figure, namely inside of the rectangle (with curved corners) created in the left hand side of the figure. The code is given below. \docume

  • Reusing parts of TikZ animation in beamer 2013-09-09

    I'd like to reuse part of an animated TikZ figure in beamer. Before switching to TikZ, I built PDF animations with IPE, and could select specific pages in the \includegraphics{} command. To do the same in TikZ, my approach would be to generate standa

  • How to align these two tikz figures better? 2013-12-16

    I'm quite new to latex and I'm trying to get two tikz figures side by side. I've honestly just looked up "tikz figures side by side" and taken code and re-adjusted it to give the figures I want, so parts of the below code might seen unnecessary.

  • How to remove white space above and below Tikz figure 2014-03-03

    I used GMS package to write a maths book, and used Tikz code genrated by Geogebra to draw the image. The problem is there are too much white space above and below Tikz figure, as in the following picture: Here is the minimal working example: \documen

  • TikZ/figure environment: Placing footnote at end of figure 2014-03-17

    Another update. This code displays essentially what I need. The only question I have at this point is if there is a way to enter the text of my "footnote" so that each line doesn't have to be placed in a separate node. \documentclass[10pt]{artic

  • Vertical and Horizontal aligment with several figures and tikz figures 2014-09-17

    This question already has an answer here: tikzpicture alignment and centering 2 answers I've been having some trouble aligning multiple figures. The problem is present with png figures and tikz figures, so I guess I am missing something. tikz figures

  • Scale TikZ figure to linewidth when relative positioning used 2011-05-03

    This question is a follow-up to How to scale a tikzpicture to \textwidth. Unfortunately I haven't been a member long enough to post comments in that thread to ask for clarification. I have some figures that I've drawn with relative positioning comman

  • how to create PDF in grayscale mode or TikZ figure only? 2011-08-15

    how to create PDF in grayscale mode? convert PDF color in PDF grayscale. I need the PDF in grayscale color. Or in TikZ figure only. --------------Solutions------------- For TikZ figures, you can use the xcolor command \selectcolormodel{gray} before o

  • How to align TikZ figures in subfigs 2011-12-15

    I use subfig to show an array of tikz figures. Unfortunately these figures are sometimes of different height, so they don't show up properly aligned: I'd like to see all nodes on the same line. I'm new to TikZ, so I'm wondering if it is possible to g

  • Scaling a TikZ figure from an external file 2011-12-17

    I would like to insert figures which were created with TikZ to my LaTeX document. I suppose that if I create the TikZ figure inside the document, that wouldn't be a problem - I'd just play with the scale value which comes right after \begin{tikzpictu

  • Using a tikz figure in an IEEE paper 2012-02-03

    I'm trying to include a tikz figure in a IEEE paper. I have the IEEE.cls, and IEEE.bib files in my current directory, but I can't seem to compile with pdflatex. I've used tikz successfully before, and I've followed my old examples, so I'm not sure wh

  • export Tikz figures to PDF 2012-02-14

    I am in the process of writing my master thesis and i am using Tikz to generate few graphs. Unfortunately, the input file for the graphs are not so small, so i already faced the problem that space limitation (solved). Nevertheless, it will take a lon

  • Wrap Caption Around TikZ Figure 2012-04-13

    I have a TikZ figure that appears as follows. The figure also has a caption. I'd like the caption to fill up that blank space in the bottom-right and bleed over into the space it current occupies. Is there a way to do this? Thanks! --------------Solu

  • Package to create TikZ Figures from R 2013-02-19

    I am wondering if there is a recommended package in order to create TikZ figures in R. In the paste I have used Matlab2TikZ to create TikZ figures in MATLAB - and I was hoping that there would be something similar for R. --------------Solutions------

  • Can we mirror a part in tikz? 2013-06-19

    After drawing a part in TikZ, is it possible to mirror that part with respect to some axis or line? MWE \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw[step=1.0,gray,thin] (0,0) grid (4,3); \draw [thick](1,1) -

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.339 (s). 13 q(s)