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

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

How to add a shadow under a picture ?

Postby Cham » Mon Mar 12, 2012 3:11 am

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}

User avatar
Stefan Kottwitz
Site Admin
Posts: 9151
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Mon Mar 12, 2012 9:23 am

Hi Cham,

you could use \shadowbox of the fancybox package.

Since you mentioned TikZ, that's not hard. Add to your preamble

  1. \usepackage{tikz}
  2. \usetikzlibrary{shadows}


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

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


Stefan
Site admin

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Mon Mar 12, 2012 4:30 pm

Thanks ! It works ! 8-)

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.

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Mon Mar 12, 2012 5:11 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}
  9. \usetikzlibrary{shadows}
  10. \definecolor{background}{RGB}{225,225,220}
  11. \pagecolor{background}
  12. \fboxsep=2mm
  13.  
  14. \begin{document}
  15. \begin{figure}[H]
  16. \centering
  17. \tikz\node[drop shadow={
  18. top color=gray,
  19. bottom color=white,
  20. %fill=gray,
  21. opacity=0.2,
  22. shadow xshift=2pt,
  23. shadow yshift=-2pt
  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
picture.jpg (73.33 KiB) Viewed 8221 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 ?

User avatar
Stefan Kottwitz
Site Admin
Posts: 9151
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Mon Mar 12, 2012 7:32 pm

For making the shadow thinner, you could use the shadow scale option and possibly remove the x and y shifting, such as

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


Stefan
Site admin

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Mon Mar 12, 2012 7:49 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.

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Mon Mar 12, 2012 9:27 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 ?

User avatar
Stefan Kottwitz
Site Admin
Posts: 9151
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Mon Mar 12, 2012 9:46 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
Site admin

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Mon Mar 12, 2012 9:53 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
  15. \shadowsize=1pt
  16. \fboxrule=0pt
  17. \fboxsep=0pt
  18. \shadowbox{\fboxsep=6pt\fcolorbox{white}{white}{\includegraphics[height=8cm]{Figures/picture.jpg}}}
  19. \caption{Another caption.}
  20. \end{figure}
  21. \end{document}

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Mon Mar 12, 2012 10:04 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
  3. \shadowsize=1pt
  4. \fboxrule=0pt
  5. \fboxsep=0pt
  6. \color{gray}
  7. \shadowbox{\fboxsep=6pt\fcolorbox{white}{white}{\includegraphics[height=8cm]{picture.jpg}}}
  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
shadow.jpg (99.72 KiB) Viewed 8206 times
Last edited by Cham on Mon Mar 12, 2012 10:40 pm, edited 1 time in total.


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 4 guests