我的文档中有很多图形,并且在同一文档中多次调用它们。当需要调用时,必须一遍又一遍地在 TeX 文件中检查图形的名称,这很麻烦。
是否存在一种解决方案,可以将图形名称与标签一起印上,就像包装上\showkeys
显示标签一样?
\documentclass[10pt]{article}
\usepackage{showkeys}
\usepackage{todonotes}
\begin{document}
\begin{figure}[t]
\centering
% \captionsetup{justification=centering}
\includegraphics[width=.7\linewidth]{fig.eps}
\caption{This is caption.}
\label{f02}
\end{figure}
\end{document}
编辑2:与CarLaTeX的回答相关。 在多图环境中,文件名会有重叠,如下图所示:
\documentclass[twoside]{IEEEtran}
\usepackage{subcaption}
\usepackage{showkeys}
\usepackage{todonotes}
\usepackage{marginnote}
\let\oldig\includegraphics
\renewcommand{\includegraphics}[2][]{\oldig[#1]{#2}\marginnote{\fbox{#2}}}
\begin{document}
\begin{figure}[t]
\centering
\includegraphics[width=.7\linewidth]{example-image-a}
\caption{This is caption $f$.}
\label{f02}
\end{figure}
\begin{figure*}[ht]
\begin{subfigure}{.49\textwidth}
% \centering
\includegraphics[width=\linewidth]{example-image-b}
\caption{ }
\label{fig2a}
\end{subfigure}
\begin{subfigure}{.49\textwidth}
% \centering
\includegraphics[width=\linewidth]{example-image-c}
\caption{ }
\label{fig2b}
\end{subfigure} \\%
\begin{subfigure}{.49\textwidth}
% \centering
\includegraphics[width=\linewidth]{example-image-a}
\caption{ }
\label{fig2c}
\end{subfigure} %
\begin{subfigure}{.49\textwidth}
% \centering
\includegraphics[width=\linewidth]{example-image-b}
\caption{ }
\label{fig2d}
\end{subfigure}
\begin{subfigure}{.49\textwidth}
% \centering
\includegraphics[width=\linewidth]{example-image-c}
\caption{ }
\label{fig2e}
\end{subfigure} %
\begin{subfigure}{.49\textwidth}
% \centering
\includegraphics[width=\linewidth]{example-image-a}
\caption{ }
\label{fig2f}
\end{subfigure} %
\caption{Kinetic energy of $f(t)$. \todo[inline]{file\_2.m } }
\label{f2}
\end{figure*}
\end{document}
答案1
这是一个解决方案\marginnote
:
\documentclass[10pt]{article}
\usepackage{showkeys}
\usepackage{todonotes}
\usepackage{marginnote}
\let\oldig\includegraphics
\renewcommand{\includegraphics}[2][]{\oldig[#1]{#2}\marginnote{\fbox{#2}}}
\begin{document}
\begin{figure}[t]
\centering
% \captionsetup{justification=centering}
%\includegraphics[width=.7\linewidth]{fig.eps}
\includegraphics[width=.7\linewidth]{example-image-a}
\caption{This is caption.\label{f02}}
\end{figure}
\end{document}
编辑:图像名称中的下划线问题可以轻松避免\detokenize
(参见这里, 例如)。
对于文件名重叠的问题,由于您的文档类在边距中没有足够的空间,我建议采用两种替代解决方案。
第一个是带有\todo[inline,color=white,nolist]{\detokenize{...}}
(该nolist
选项使得该注释不会打印在todonote列表中)的,但是这会稍微改变原始文档中的间距:
\documentclass[twoside]{IEEEtran}
\usepackage[T1]{fontenc}% <-- to have _ in the name of the image included
\usepackage{subcaption}
\usepackage{showkeys}
\usepackage{todonotes}
\let\oldig\includegraphics
% \detokenize to have the _ printed, nolist not to heve to todonote printed in the todonote list:
\renewcommand{\includegraphics}[2][]{\oldig[#1]{#2}\todo[inline,color=white,nolist]{\detokenize{#2}}}
\begin{document}
\begin{figure}[t]
%\centering
\includegraphics[width=.7\linewidth]{example-image-a}
\caption{This is caption $f$.}
\label{f02}
\end{figure}
\begin{figure*}[ht]
\begin{subfigure}{.49\textwidth}
% \centering
\includegraphics[width=\linewidth]{fig_2.eps}
\caption{\label{fig2a}}
\end{subfigure}
\begin{subfigure}{.49\textwidth}
% \centering
\includegraphics[width=\linewidth]{example-image-c}
\caption{\label{fig2b}}
\end{subfigure} \\%
\begin{subfigure}{.49\textwidth}
% \centering
\includegraphics[width=\linewidth]{example-image-a}
\caption{\label{fig2c}}
\end{subfigure} %
\begin{subfigure}{.49\textwidth}
% \centering
\includegraphics[width=\linewidth]{example-image-b}
\caption{\label{fig2d}}
\end{subfigure}
\begin{subfigure}{.49\textwidth}
% \centering
\includegraphics[width=\linewidth]{example-image-c}
\caption{\label{fig2e}}
\end{subfigure} %
\begin{subfigure}{.49\textwidth}
% \centering
\includegraphics[width=\linewidth]{example-image-a}
\caption{\label{fig2f}}
\end{subfigure} %
\caption{Kinetic energy of $f(t)$.\todo[inline]{file\_2.m}\label{f2}}
\end{figure*}
\end{document}
输出如下:
第二种解决方案是使用\tikz[overlay]{...}
,我更喜欢这个,因为它不会改变原始文档中的间距。
如果想要节点背景透明,删除fill=white
。如果想要改变节点位置,更改坐标at (-2,.5)
:
\documentclass[twoside]{IEEEtran}
\usepackage[T1]{fontenc}% <-- to have _ in the name of the image included
\usepackage{subcaption}
\usepackage{showkeys}
\usepackage{todonotes}
\let\oldig\includegraphics
\renewcommand{\includegraphics}[2][]{\oldig[#1]{#2}\tikz[overlay]{%
\node[draw, fill=white] at (-2,.5) {\detokenize{#2}};}
}% \detokenize to have the _ printed
\begin{document}
\begin{figure}[t]
%\centering
\includegraphics[width=.7\linewidth]{example-image-a}
\caption{This is caption $f$.}
\label{f02}
\end{figure}
\begin{figure*}[ht]
\begin{subfigure}{.49\textwidth}
% \centering
\includegraphics[width=\linewidth]{fig_2.eps}
\caption{\label{fig2a}}
\end{subfigure}
\begin{subfigure}{.49\textwidth}
% \centering
\includegraphics[width=\linewidth]{example-image-c}
\caption{\label{fig2b}}
\end{subfigure} \\%
\begin{subfigure}{.49\textwidth}
% \centering
\includegraphics[width=\linewidth]{example-image-a}
\caption{\label{fig2c}}
\end{subfigure} %
\begin{subfigure}{.49\textwidth}
% \centering
\includegraphics[width=\linewidth]{example-image-b}
\caption{\label{fig2d}}
\end{subfigure}
\begin{subfigure}{.49\textwidth}
% \centering
\includegraphics[width=\linewidth]{example-image-c}
\caption{\label{fig2e}}
\end{subfigure} %
\begin{subfigure}{.49\textwidth}
% \centering
\includegraphics[width=\linewidth]{example-image-a}
\caption{\label{fig2f}}
\end{subfigure} %
\caption{Kinetic energy of $f(t)$.\todo[inline]{file\_2.m}\label{f2}}
\end{figure*}
\end{document}
答案2
有一种可能性是:
\documentclass[10pt]{article}
\usepackage{graphicx}
\begin{document}
\let\origincludegraphics\includegraphics
\def\includegraphics[#1]#2{%
% \marginpar and \vadjust would be nice here,
% but we're in the wrong mode for either
\vbox to 0pt{\hbox to \linewidth{\hfil\hbox to 0pt{file: #2\hss}}\vss}\par
\origincludegraphics[#1]{#2}}
\begin{figure}[t]
\centering
\includegraphics[width=.7\linewidth]{spiral.pdf}
\caption{This is caption.}
\label{f02}
\end{figure}
\end{document}
这与 没有任何关系\label
,也不能,因为\label
无法“看到”\includegraphics
论点(这是您在澄清的问题中想要显示的)。
这说明了一种通用技术(在某些圈子里称为“monkeypatching”!),其中您使用保存命令的原始版本\let
,然后定义它的新版本,该新版本在调用原始版本之前或之后执行一些有用的工作。
(其内容\vbox
可能比那里显示的更复杂或更简单 - 那里的内容可能足以用于草稿模式功能)