How to black out a figure for confidential reasons?

Just define a Btikzpicture environment that can behave differently under a set conditional and use it for the pictures that you want to selectively omit:

\documentclass{article}
\usepackage{tikz}

\newif\ifsecret
% \secrettrue % uncomment for the hidden version

\ifsecret
%%% code for blanking TikZ pictures
\newsavebox{\Btpbox}
\newenvironment{Btikzpicture}
  {\begin{lrbox}{\Btpbox}\begin{tikzpicture}}
  {\end{tikzpicture}\end{lrbox}%
   \fboxsep=-\fboxrule\fbox{\omission\phantom{\usebox{\Btpbox}}}}

\newcommand{\omission}{\makebox[0pt][l]{\,\tiny OMITTED\strut}}
%%%
\else
%%% code for normal printing
\newenvironment{Btikzpicture}{\tikzpicture}{\endtikzpicture}
%%%
\fi    

\begin{document}
\tikzset{
    every node/.style={
        circle,
        draw,
        solid,
        fill=black!50,
        inner sep=0pt,
        minimum width=4pt
    }
}
\begin{Btikzpicture}[thick,scale=0.8,->,shorten >=2pt]
    \draw (0,0) node {} -- (1,1) node {};
    \draw (1,1) node {} -- (2,1) node {};
    \draw (2,1) node {} -- (3,2) node {};
    \draw (3,2) node {} -- (4,1) node {};

    \draw  (0,2) node {} -- (1,1) node {};
    \draw (1,2) node {} -- (2,1) [dashed] node {};
    \draw (2,1) node {} -- (3,2) node {};
    \draw (3,2) node {} -- (4,1) node {};

    \draw (2,1) node {} -- (3,0) [dashed] node {};
    \draw (2,1) node {} -- (2,0) [dashed] node {};
    \draw (3,0) node {} -- (4,0) [dashed] node {};
    \draw (3,0) node {} -- (4,-1) [dashed] node {};
    \draw (1,1) node {} -- (1,0) [dashed] node {};
\end{Btikzpicture}

\end{document}

(The picture code is taken from an answer by Jake.)

When \secrettrue is uncommented, only a frame of the correct size will be drawn; only the metric information will be in the final output.


You can use adjustbox to replace the content with a black (or gray, to save ink) rectangle.

Note that this solution will not write the censored content into the PDF.

\documentclass{article}

\usepackage{adjustbox}
\usepackage{tikz}

\iffalse
\newenvironment{ctikzpicture}{%
    \tikzpicture
}{%
    \endtikzpicture
}
\else
\newenvironment{ctikzpicture}{%
    \adjustbox{precode=\phantom,bgcolor=black!10}\bgroup
    \tikzpicture
}{%
    \endtikzpicture
    \egroup
}
\fi

\begin{document}

\begin{ctikzpicture}[thick]
    \draw (0,0) -- (10,10);
    \node at (5,5) {Secret information};
\end{ctikzpicture}

\end{document}

With recent version of adjustbox (i.e. v1.1 2018/04/08) you can just write phantom as a key and also add some "Censored" text on top of it.

\documentclass{article}

\usepackage{adjustbox}[2018/04/08]
\usepackage{tikz}

\iffalse
\newenvironment{ctikzpicture}{%
    \tikzpicture
}{%
    \endtikzpicture
}
\else
\newenvironment{ctikzpicture}{%
    \adjustbox{phantom,bgcolor=black!10,foreground={rotate=45}{\sffamily Censored!}}\bgroup
    \tikzpicture
}{%
    \endtikzpicture
    \egroup
}
\fi

\usepackage{blindtext}
\begin{document}
\blindtext

\begin{ctikzpicture}[thick]
    \draw (0,0) -- (10,10);
    \node at (5,5) {Secret information};
\end{ctikzpicture}

\blindtext
\end{document}

enter image description here


The \censorbox command from my censor package can block out boxed material like figures, tables, etc. Here is an excerpt from the docs:

enter image description here enter image description here