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 would like to replace some figures in a document with a black frame of the same size as the figure, such as that which you get when using \includegraphics in draft mode. However, this places the name of the figure file inside the framed box. Is there a way to replace this text with centered text stating
Figure removed due to copyright restrictions?

share|improve this question
add comment

1 Answer

A suggestion can be the combination of collectbox, adjustbox and tikz.

I tried to avoid TikZ but I wasn't able to create the red rectangle with adjustbox.

The code provides two things:

  1. A switch do print the image or the copyright information. You can choose by \copyrightimagefalse or \copyrightimagetrue.
  2. Instead of using includegraphics you must use \copyrightimage to work with the previous switch.

The Code

\documentclass{article}
\usepackage{mwe}% or load ’graphicx’ and ’blindtext’ manually
\usepackage{xcolor}
\usepackage{adjustbox}
\usepackage{collectbox}
\usepackage{tikz}
\newif\ifcopyrightimage
\copyrightimagefalse
\newcommand*\copyrightimage[2][]{%
\collectbox{%
  \ifcopyrightimage
  \tikz[outer sep=0pt]\node[fill=red!20,minimum height=\totalheight,minimum width=\width]{%
       \smash{\parbox{\width}{\centering\large\bfseries Figure removed due to copyright restrictions}}
   };%
  \else
     \BOXCONTENT
\fi%
  }{\adjincludegraphics[#1]{#2}}%
}

\begin{document}
\begin{figure}[!ht]
\centering
\copyrightimage[width=0.48\linewidth]{example-image-a}
\caption{set \texttt{\string\copyrightimagefalse}}
\end{figure}
\blindtext

\begin{figure}[!ht]
\centering\copyrightimagetrue
\copyrightimage[width=0.48\linewidth]{example-image-a}
\caption{set \texttt{\string\copyrightimagetrue}}
\end{figure}
\blindtext
\end{document}
share|improve this answer
    
Thanks for your suggestion. However, I cannot seem to get this code working, even if I simply copy-and-paste it and change only the image file. pdfLatex keeps on complaining that \copyrightimage is an undefined control sequence: Undefined control sequence. \\copyrightimage ...ENT \fi }{\adjincludegraphics [#1]{#2}} l.24 \copyrightimage[width=0.48\linewidth]{dice} ? Could you please confirm if the code works as is? Thanks again... –  Miguel May 20 '12 at 17:11
    
@Miguel: Please make an update of your TeX distribution. –  Marco Daniel May 20 '12 at 17:17
    
Thanks - the code now runs! But the box is too wide and shifted to the right (lies outside of the text margins when the image has width = \textwidth). Compare: \begin{figure}[!ht] \centering \includegraphics[draft, width=\textwidth]{some-image} \end{figure} \blindtext versus \begin{figure}[!ht] \centering\copyrightimagetrue \copyrightimage[width=\textwidth]{some-image} \end{figure} \blindtext –  Miguel May 21 '12 at 7:13
    
@miguel I will test it later and change the example. –  Marco Daniel May 21 '12 at 9:48
    
@Miguel: You use \includegraphics instead of \copyrightimage. As I wrote I defined a new command instead of redefining includegraphics –  Marco Daniel May 21 '12 at 18:32
show 1 more 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.