我想制作阴影图像边框。我当前的解决方案是使用\shadowbox
:
\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{fancybox, graphicx}
\begin{document}
\shadowsize=1mm
\color{blue}
\shadowbox{\fboxsep=3mm\fcolorbox{white}{white}{\includegraphics[width=12cm,height=8cm,keepaspectratio]{example-image-a}}}
\end{document}
因此 1) 必须有一个白色边框 2) 投射阴影。但这会创建一个非常“简单”的实心阴影:
我想实现更加“模糊的效果”。
基于这答案我写了类似这样的内容:
\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage[skins]{tcolorbox}
\usepackage{fancybox, graphicx}
\begin{document}
\begin{center}
\begin{tcolorbox}[enhanced,width=12cm,height=8cm, center upper,
fontupper=\large\bfseries,drop fuzzy shadow southeast,
boxrule=0.4pt,sharp corners,colframe=yellow!80!white,colback=white!10]
\includegraphics[width=12cm,height=7.9cm,keepaspectratio]{example-image-a}
\end{tcolorbox}
\end{center}
\end{document}
但正如您所看到的,我需要这个颜色框根据我的图像进行缩放(最大尺寸为 8x12cm,保持纵横比)。
我看到一些过于复杂的答案并应用了一些规则,但我确实相信一定有一个更简单的解决方案。
此外 - 上述解决方案实际上可以将阴影投射到世界的 4 个侧面,而不仅仅是southeast
等等?
答案1
\tcolorbox
正在使用\linewidth
或指定的尺寸width
和,但height
考虑到内部内容,这可能是错误的。
\tcbox
根据内部内容改变尺寸并适当缩放。
我已经定义了\whiteshadowbox
一些选项,定心是通过before
和after
键完成的。
\documentclass[12pt]{article}
\usepackage[skins]{tcolorbox}
\newtcbox{\whiteshadowbox}[1][]{%
enhanced,
center upper,
fontupper=\large\bfseries,
drop fuzzy shadow southeast,
boxrule=0.4pt,
sharp corners,
colframe=blue,
colback=white!10,
before={\begin{center}},
after={\end{center}},
#1%
}
\begin{document}
\whiteshadowbox{%
\includegraphics[width=12cm,height=7.9cm,keepaspectratio]{example-image-a}
}
\whiteshadowbox[colback=green]{%
\includegraphics[width=5cm,height=6cm,keepaspectratio]{example-image-a}
}
\end{document}
使用halo
选项更新
\documentclass[12pt]{article}
\usepackage[skins]{tcolorbox}
\newtcbox{\whiteshadowbox}[1][]{%
enhanced,
center upper,
fontupper=\large\bfseries,
fuzzy halo={0.9mm with gray},
% drop fuzzy shadow southeast,
boxrule=0.4pt,
sharp corners,
colframe=blue,
colback=white!10,
before={\begin{center}},
after={\end{center}},
#1%
}
\begin{document}
\whiteshadowbox{%
\includegraphics[width=12cm,height=7.9cm,keepaspectratio]{example-image-a}
}
\whiteshadowbox[colback=green]{%
\includegraphics[width=5cm,height=6cm,keepaspectratio]{example-image-a}
}
\end{document}
使用size=tight
和boxsep=1cm
设置
\documentclass[12pt]{article}
\usepackage[skins]{tcolorbox}
\tcbset{
halobox/.style={
enhanced,
center upper,
fontupper=\large\bfseries,
size=tight,
boxsep=1cm,
fuzzy halo={0.9mm with gray},
boxrule=0.4pt,
sharp corners,
colframe=blue,
colback=white!10,
before={\begin{center}},
after={\end{center}}}
}
\newtcbox{\whiteshadowbox}[1][]{%
halobox,
#1%
}
\begin{document}
\whiteshadowbox{%
\includegraphics[width=12cm,height=7.9cm,keepaspectratio]{example-image-a}
}
\whiteshadowbox[colback=green]{%
\includegraphics[width=5cm,height=6cm,keepaspectratio]{example-image-a}
}
\end{document}
答案2
该pstricks
模块非常简单pst-blur
:
\documentclass[12pt, svgnames]{article}
\usepackage{graphicx}
\usepackage{pst-blur}
%\usepackage{auto-pst-pdf}% to compile with pdflatex --enable-write18 (MiKTeX) or pdflatex --shell-escape (TeXLive, MacTeX)
\begin{document}
\begin{pspicture}
\psframebox[linecolor = RoyalBlue, framesep = 4mm, shadow, blur, shadowcolor = RoyalBlue, shadowsize = 1.5mm ]{%
\includegraphics[width = 12cm, height = 8cm, keepaspectratio]{example-image-a}}
\end{pspicture}
\end{document}