后续问题:如何在图形位置插入自定义文本 - 替换框的对齐方式

后续问题:如何在图形位置插入自定义文本 - 替换框的对齐方式

该问题是此处问题的后续问题:https://tex.stackexchange.com/a/56609/93064

目的是用包含相关文本的框替换图形(例如,由于版权原因删除的图形)。该框必须与原始图形的大小和位置完全相同,以便与包含图形的完整文档相比保留页码等。

Marco Daniel 建议的代码几乎完全满足我的需要(见下文,对颜色和字体稍作修改):

\usepackage{tikz}
\newif\ifcopyrightimage
\copyrightimagefalse
\newcommand*\copyrightimage[2][]{%
\collectbox{%
  \ifcopyrightimage
  \tikz[outer sep=0pt]\node[fill=gray!20,minimum height=\totalheight,minimum width=\width]{%
       \smash{\parbox{\width}{\centering Figure removed from the electronic copy of this thesis due to copyright restrictions}}
   };%
  \else
     \BOXCONTENT
\fi%
  }{\adjincludegraphics[#1]{#2}}%
}

在文档中...

\begin{figure}[htbp]
\centering\copyrightimagetrue
\copyrightimage[width=0.48\linewidth]{example-image-a}
\caption{Caption}
\end{figure}

在哪里

\copyrightimagetrue \copyrightimage

取代

\includegraphics

然而,正如 Miguel 所说,替换框实际上比原来的框稍宽,并且略微向右移动。这意味着它延伸到我的页边距,而这些图的宽度几乎与页面一样宽。

由于之前没有使用过 tikz,我正在努力寻找修改哪里的方法以尝试解决问题。

提前谢谢了。

MWE(请原谅笨拙的代码):

\RequirePackage[pagewise]{lineno} 
\documentclass[british, a4paper, twoside, 12pt,openright]{report}
\RequirePackage[ignoreall, a4paper, margin=25mm, bindingoffset=10mm]{geometry}


\usepackage{review_emph_etal}
\usepackage[english]{babel}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{xspace}
\usepackage{multirow}
\usepackage[figuresright]{rotating}
\usepackage{lscape}
\usepackage{pbox}
\usepackage{color}
\usepackage{tabularx,ragged2e}
\usepackage{afterpage}
\usepackage{rotating}
\usepackage{amsfonts}
\usepackage{fixltx2e} % allows to use \textsubscript
\usepackage{tablefootnote}
\usepackage{footnote}
\usepackage[export]{adjustbox}
\usepackage{multicol}
\usepackage{etoolbox}
\usepackage{pifont}
\usepackage{colortbl}

%%%%%%%%%%%%%%
\usepackage{tikz}
\newif\ifcopyrightimage
\copyrightimagefalse
\newcommand*\copyrightimage[2][]{%
\collectbox{%
\ifcopyrightimage
\tikz[outer sep=0pt]\node[fill=gray!20,minimum height=\totalheight,minimum width=\width]{%
   \smash{\parbox{\width}{\centering Figure removed from the electronic copy of this thesis due to copyright restrictions}}%
};%
  \else%
 \BOXCONTENT%
\fi%
}{\adjincludegraphics[#1]{#2}}%
}
%%%%%%%%%%%

\begin{document}

This is the normal figure:
\begin{figure}[htbp]
  \centering 
\includegraphics[width=1.00\textwidth]{FigureFilename}
 \caption{Caption}
 \label{Label}
\end{figure}

This figure is supposed to be a greyed-out version of the one above, with the same positioning and width.
\begin{figure}[htbp]
  \centering \copyrightimagetrue
\copyrightimage[width=1.00\textwidth]{FigureFilename}
 \caption{Caption}
 \label{Label}
\end{figure}

\end{document}

答案1

干得好。

假设图像文件存在(并且具有特定尺寸),目的是生成与生成的大小相同的空间或占位符,同时不让读者看到图像(也可以减小草稿中的文件大小)。您可以执行类似下面的操作,测量图像,然后在其位置插入 tikz 节点。通过更改代码,您可以删除或更改内部文本,并在不同时间删除边框。

我通过定义 \includegraphics 的变体(\includegraphicsd)来实现这一点

\documentclass{article}
\usepackage{tikz}
\usepackage{xparse}
\usepackage{graphicx}

\newsavebox\abimagebox
\NewDocumentCommand \includegraphicsd { O{} m }{%
  \sbox\abimagebox{\includegraphics[#1]{#2}}%
  \begin{tikzpicture}
    \node[
      draw,
      dashed,
      text width=\the\dimexpr\wd\abimagebox-.4pt\relax,
      minimum height=\the\dimexpr\ht\abimagebox-.4pt\relax,
      align=center,
      inner sep=0,
    ]{This is white};%
  \end{tikzpicture}%
}

\begin{document}

%This image is shown
\begin{figure}[htbp]
  \centering
  \includegraphics[width=0.345\textwidth]{example-image-a}
  \caption{Close up of an opossum, part of the genus of piglet.}
\end{figure}

%This one is not shown
\begin{figure}[htbp]
  \centering
  \includegraphicsd[width=0.345\textwidth]{example-image-a}
  \caption{Close up of an opossum, part of the genus of piglet.}
\end{figure}

\end{document} 

在此处输入图片描述

相关内容