## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ How to add a shadow under a picture ? Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

How can I modify the following compilable code to add a gray drop shadow to the picture (including its frame) ?
I really don't understand the TikZ package. Is there a simple way to add the shadow ?

\documentclass[12pt,letterpaper,twoside]{book}\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}\usepackage[french]{babel}\usepackage{graphicx}\usepackage[dvipsnames]{xcolor}\usepackage{here}\definecolor{background}{RGB}{225,225,220}\pagecolor{background}\fboxsep=2mm \begin{document}bla bla bla\medskip\medskip	\begin{figure}[H]		\centering		\fcolorbox{black}{white}{\includegraphics[height=8cm]{picture.jpg}}		\caption{A caption.}	\end{figure}\end{document}

Stefan Kottwitz
Posts: 9019
Joined: Mon Mar 10, 2008 9:44 pm
Hi Cham,

you could use \shadowbox of the fancybox package.

\usepackage{tikz}\usetikzlibrary{shadows}

and in your code you could use, for example, \node [drop shadow] :

\begin{figure}[H]\centering   \tikz\node [drop shadow]     {\fcolorbox{black}{white}{\includegraphics[height=8cm]{picture.png}}};   \caption{A caption.}\end{figure}

Stefan

Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm
Thanks ! It works !

But how can I make the shadow fuzzy ?

Also, the drop shadow isn't properly placed. I tried to play with the shadow xshift and shadow yshift options, but it's not sufficient, apparently.

Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm
Here's a compilable code. The drop shadow isn't right. How can I improve it ?

The shadow thickness is too strong. I don't know how to change it.
And is it possible to make the shadow fuzzy (blurry) ?

The shadow should be very subtle, with the same thickness at the right side and below the picture's frame. Currently, it's very hard to adjust the shadow. There must be a simpler way to do this.

\documentclass[12pt,letterpaper,twoside]{book}\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}\usepackage[french]{babel}\usepackage{graphicx}\usepackage[dvipsnames]{xcolor}\usepackage{here}\usepackage{tikz}\usetikzlibrary{shadows}\definecolor{background}{RGB}{225,225,220}\pagecolor{background}\fboxsep=2mm \begin{document}	\begin{figure}[H]		\centering		\tikz\node[drop shadow={			top color=gray,			bottom color=white,			%fill=gray,			opacity=0.2,			shadow xshift=2pt,			shadow yshift=-2pt			}]		{\fcolorbox{black}{white}{\includegraphics[height=8cm]{picture.jpg}}};		\caption{A caption.}	\end{figure}\end{document}

EDIT : I'm trying to do this effect :
picture.jpg (73.33 KiB) Viewed 7864 times

However, the shadow isn't right yet. The thickness should be exactly the same at the right and below the frame, with the same offset on the lower-left and upper-right corners. How ?

Stefan Kottwitz
Posts: 9019
Joined: Mon Mar 10, 2008 9:44 pm
For making the shadow thinner, you could use the shadow scale option and possibly remove the x and y shifting, such as

\tikz\node[drop shadow={     shadow scale=0.98,     top color=gray,     opacity=0.5   }]   {\fcolorbox{black}{white}{\includegraphics[height=8cm]{picture.png}}};

Stefan

Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm
Well then, the offset isn't right. It's still slightly larger on the right side.

Take note that the picture isn't square. It's of rectangular shape, so I suspect it may be related to that.

Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm
Is there any other way to drop a shadow under a picture, in LaTeX ? I think that the TikZ way is very cumbersome. Is there a way to add a shadow to a picture (including its frame, as defined in my example above), using another package, and that let you use a color/transparency as an option ?

Stefan Kottwitz
Posts: 9019
Joined: Mon Mar 10, 2008 9:44 pm
LaTeX is mainly for typesetting text. I guess you look for a graphics software. A graphics package such as TikZ would be an option though, which is capable of drawing even faded shadows, but now it's out of the question. Try Inkscape for example.

Stefan

Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm
I've found a good combination with fancybox, without TikZ. However, is there a way to add some transparency or color to the fancybox shadow ? Currently, the black lines are too heavy :

\documentclass[12pt,letterpaper,twoside]{book}\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}\usepackage[french]{babel}\usepackage{graphicx}\usepackage[dvipsnames]{xcolor}\usepackage{here}\usepackage{fancybox}\definecolor{background}{RGB}{230,225,220}\pagecolor{background} \begin{document}	\begin{figure}[H]		\centering		\shadowsize=1pt		\fboxrule=0pt		\fboxsep=0pt		\shadowbox{\fboxsep=6pt\fcolorbox{white}{white}{\includegraphics[height=8cm]{Figures/picture.jpg}}}		\caption{Another caption.}	\end{figure}\end{document}

Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm
Hmmm, maybe this is an hack ?

I've found a way to change the fancybox color, but I need to add another color directive since it's also changing the caption's text color :

	\begin{figure}[H]		\centering		\shadowsize=1pt		\fboxrule=0pt		\fboxsep=0pt		\color{gray}		\shadowbox{\fboxsep=6pt\fcolorbox{white}{white}{\includegraphics[height=8cm]{picture.jpg}}}		\color{black}		\caption{Another caption.}	\end{figure}

Is there a better way to achieve this ?

Here's a preview of the final effect, which I think is VERY nice !

shadow.jpg (99.72 KiB) Viewed 7849 times
Last edited by Cham on Mon Mar 12, 2012 10:40 pm, edited 1 time in total.