5

I want to make a shaded image border. My current solution is using \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}

So 1) there must be a white border 2) which casts a shadow. But this creates a very "simple", solid shadow: enter image description here

I would like to achieve a more "blurry effect".

Based on this answer I wrote something like this:

\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}

but as you can see, I need this colorbox to scale with my image (which is max 8x12cm, keeping aspect ratio). enter image description here

I saw some overly complicated answers with applying some rules but I really believe there must be a simpler solution.

Besides - can the above solution actually drop shadows to 4 sides of the world, not only southeast etc?

7

\tcolorbox is either using the \linewidth or the sizes specified with width and height which may be wrong considering the internal content.

\tcbox changes the size according to the inner content and scales appropriately.

I have defined a \whiteshadowbox with some options, the centering is done with the before and after keys.

\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}

enter image description here

Update with halo option

\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}

With size=tight and boxsep=1cm settings

\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}

enter image description here

  • Instead of fuzzy shadow use fuzzy halo to get a 'full shadow' – user31729 Dec 27 '17 at 16:50
  • Thank you. Is there a way to manipulate the size of the box? Let's say that in your latter example I would like the green area to be 1cm wide in each directon? – kch Dec 28 '17 at 10:06
  • @kch: \whiteshadowbox[colback=green,boxsep=1cm]{...} should work – user31729 Dec 28 '17 at 13:17
  • @kch: Added a third example (without screen shot, however. See the halobox style settings. – user31729 Dec 28 '17 at 21:35
7

It's is very simple with the pstricks module 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} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.