## 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: 937
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 ?

1. \documentclass[12pt,letterpaper,twoside]{book}
2. \usepackage[T1]{fontenc}
3. \usepackage[utf8]{inputenc}
4. \usepackage[french]{babel}
5. \usepackage{graphicx}
6. \usepackage[dvipsnames]{xcolor}
7. \usepackage{here}
8. \definecolor{background}{RGB}{225,225,220}
9. \pagecolor{background}
10. \fboxsep=2mm
11.
12. \begin{document}
13. bla bla bla
14. \medskip
15. \medskip
16. \begin{figure}[H]
17. \centering
18. \fcolorbox{black}{white}{\includegraphics[height=8cm]{picture.jpg}}
19. \caption{A caption.}
20. \end{figure}
21. \end{document}

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

you could use \shadowbox of the fancybox package.

1. \usepackage{tikz}

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

1. \begin{figure}[H]
2. \centering
4. {\fcolorbox{black}{white}{\includegraphics[height=8cm]{picture.png}}};
5. \caption{A caption.}
6. \end{figure}

Stefan

Cham
Posts: 937
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: 937
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.

1. \documentclass[12pt,letterpaper,twoside]{book}
2. \usepackage[T1]{fontenc}
3. \usepackage[utf8]{inputenc}
4. \usepackage[french]{babel}
5. \usepackage{graphicx}
6. \usepackage[dvipsnames]{xcolor}
7. \usepackage{here}
8. \usepackage{tikz}
10. \definecolor{background}{RGB}{225,225,220}
11. \pagecolor{background}
12. \fboxsep=2mm
13.
14. \begin{document}
15. \begin{figure}[H]
16. \centering
18. top color=gray,
19. bottom color=white,
20. %fill=gray,
21. opacity=0.2,
24. }]
25. {\fcolorbox{black}{white}{\includegraphics[height=8cm]{picture.jpg}}};
26. \caption{A caption.}
27. \end{figure}
28. \end{document}

EDIT : I'm trying to do this effect :
picture.jpg (73.33 KiB) Viewed 11727 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: 9604
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

3. top color=gray,
4. opacity=0.5
5. }]
6. {\fcolorbox{black}{white}{\includegraphics[height=8cm]{picture.png}}};

Stefan

Cham
Posts: 937
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: 937
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: 9604
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: 937
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 :

1. \documentclass[12pt,letterpaper,twoside]{book}
2. \usepackage[T1]{fontenc}
3. \usepackage[utf8]{inputenc}
4. \usepackage[french]{babel}
5. \usepackage{graphicx}
6. \usepackage[dvipsnames]{xcolor}
7. \usepackage{here}
8. \usepackage{fancybox}
9. \definecolor{background}{RGB}{230,225,220}
10. \pagecolor{background}
11.
12. \begin{document}
13. \begin{figure}[H]
14. \centering
16. \fboxrule=0pt
17. \fboxsep=0pt
19. \caption{Another caption.}
20. \end{figure}
21. \end{document}

Cham
Posts: 937
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 :

1. \begin{figure}[H]
2. \centering
4. \fboxrule=0pt
5. \fboxsep=0pt
6. \color{gray}
8. \color{black}
9. \caption{Another caption.}
10. \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 11712 times
Last edited by Cham on Mon Mar 12, 2012 10:40 pm, edited 1 time in total.