这篇文章是对对示例图像进行着色,但保留默认的暗色
考虑一下代码
\documentclass{article}
\usepackage{xcolor,graphicx}
\usepackage{caption}
\makeatletter
\define@key{Gin}{color}{\def\Gin@color{#1}}
\setlength{\fboxsep}{0pt}
\let\oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[2][]{%
\ifnum\pdfstrcmp{#2}{example-image}=0%
\begingroup
\setkeys{Gin}{color=red,#1} % Sets default color to be red
\colorbox{\Gin@color}{\phantom{\oldincludegraphics[#1]{#2}}}%
\endgroup
\else
\oldincludegraphics[#1]{#2}%
\fi
}
\makeatother
\begin{document}
\begin{figure}[!htb]
\centering
\includegraphics[width=10em,height=13em]{example-image}
\captionsetup{labelformat=empty} \vskip 8pt
\caption{\textbf{\scshape{\large Red Figure}}}
\end{figure}
\begin{figure}[!htb]
\centering
\includegraphics[width=10em,height=13em,color=blue]{example-image}
\captionsetup{labelformat=empty} \vskip 8pt
\caption{\textbf{\scshape{\large Blue Figure}}}
\end{figure}
\begin{figure}[!htb]
\centering
\includegraphics[width=10em,height=13em]{example-image-a}
\captionsetup{labelformat=empty} \vskip 8pt
\caption{\textbf{\scshape{\large How to Color Shade, Say Green, Figure A?}}}
\end{figure}
\end{document}
产生输出
我想在最后一张图中添加一些(绿色)颜色阴影(example-image-a
)。但是,当我\includegraphics[width=10em,height=13em]{example-image-a}
用\includegraphics[width=10em,height=13em,color=green]{example-image-a}
替换时,我得到了与所示相同的示例图像 a。
这也许并不奇怪,因为如果color=green
在这种情况下起作用,我想“A”及其相关线条可能会被消灭。
问题:这是否可行?如果可以,我该如何添加一些(绿色)颜色阴影到example-image-a
以便图像着色,但 A 及其相关线条仍然可见?这是否涉及某种彩色透明饰面?
谢谢。
答案1
嗯,基本上你只需要在图像上放置一个半透明的规则:
\documentclass{article}
\usepackage{xcolor,graphicx}
\usepackage{transparent}
\begin{document}
\begin{figure}[!htb]
\centering
\includegraphics[width=10em,height=13em]{example-image}\llap{\texttransparent{0.5}{\color{green}\rule{10em}{13em}}}
\caption{How to Color Shade, Say Green, Figure A?}
\end{figure}
\end{document}