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
Stefan Kottwitz
Site Admin
Posts: 9152
Joined: Mon Mar 10, 2008 9:44 pm

Re: How to add a shadow under a picture ?

Postby Stefan Kottwitz » Mon Mar 12, 2012 10:17 pm

I would define a macro for that, in the preamble. Within the figure environment, I would call that macro. So further changes or adjustments would be easy and consistent.

Stefan
Site admin

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

Postby Cham » Mon Mar 12, 2012 10:24 pm

Hmm, I'm ain't an expert on this. How do you suggest to define that macro ?

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

Postby Stefan Kottwitz » Mon Mar 12, 2012 11:03 pm

Macros are an important strength of LaTeX. Define a macro once, and use it many times. For example, in the preamble:

  1. \newcommand{\shadowpicture}[1]{%
  2. \shadowsize=1pt
  3. \fboxrule=0pt
  4. \fboxsep=0pt
  5. \color{gray}
  6. \shadowbox{\fboxsep=6pt\fcolorbox{white}{white}{#1}}
  7. \normalcolor
  8. }


Later, in the document:

  1. \begin{figure}[H]
  2. \centering
  3. \shadowpicture{\includegraphics[height=8cm]{picture.jpg}}
  4. \caption{Another caption.}
  5. \end{figure}


Macros are not just for saving typing, but for consistency and easy changes.

Stefan
Site admin

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

Postby Cham » Mon Mar 12, 2012 11:08 pm

Works perfectly well ! :D

Thanks Stefan ! (by the way, see the preview in my last message, on the previous page...)

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

Postby Stefan Kottwitz » Mon Mar 12, 2012 11:17 pm

The preview looks nice!

Regarding macros, try defining macros for all which you possibly need several times, also to make a logical document. For example, I would not even use \textbf or \textit in a document - but I would define \keyword etc. for such emphasis. These macros could call \textbf etc. And I could change that for the whole document whenever I like.

Stefan
Site admin

bloomy
Posts: 2
Joined: Thu Mar 20, 2014 12:44 am

Postby bloomy » Thu Mar 20, 2014 1:18 am

I found a very nice solution on http://tex.stackexchange.com/questions/81842/creating-a-drop-shadow-with-guassian-blur

It certainly looks like its exactly what you are looking for, and I was also. Next thing is I'd like to make this part of a class or a module.

Let me know how you go.
Cheers


Here is the code
  1. \documentclass{article}
  2. % put all this in the preamble
  3. \usepackage{tikz}
  4. \usetikzlibrary{shadows,calc}
  5.  
  6. % code adapted from http://tex.stackexchange.com/a/11483/3954
  7.  
  8. % some parameters for customization
  9. \def\shadowshift{3pt,-3pt}
  10. \def\shadowradius{6pt}
  11.  
  12. \colorlet{innercolor}{black!60}
  13. \colorlet{outercolor}{gray!05}
  14.  
  15. % this draws a shadow under a rectangle node
  16. \newcommand\drawshadow[1]{
  17. \begin{pgfonlayer}{shadow}
  18. \shade[outercolor,inner color=innercolor,outer color=outercolor] ($(#1.south west)+(\shadowshift)+(\shadowradius/2,\shadowradius/2)$) circle (\shadowradius);
  19. \shade[outercolor,inner color=innercolor,outer color=outercolor] ($(#1.north west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$) circle (\shadowradius);
  20. \shade[outercolor,inner color=innercolor,outer color=outercolor] ($(#1.south east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$) circle (\shadowradius);
  21. \shade[outercolor,inner color=innercolor,outer color=outercolor] ($(#1.north east)+(\shadowshift)+(-\shadowradius/2,-\shadowradius/2)$) circle (\shadowradius);
  22. \shade[top color=innercolor,bottom color=outercolor] ($(#1.south west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$) rectangle ($(#1.south east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$);
  23. \shade[left color=innercolor,right color=outercolor] ($(#1.south east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$) rectangle ($(#1.north east)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$);
  24. \shade[bottom color=innercolor,top color=outercolor] ($(#1.north west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$) rectangle ($(#1.north east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$);
  25. \shade[outercolor,right color=innercolor,left color=outercolor] ($(#1.south west)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$) rectangle ($(#1.north west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$);
  26. \filldraw ($(#1.south west)+(\shadowshift)+(\shadowradius/2,\shadowradius/2)$) rectangle ($(#1.north east)+(\shadowshift)-(\shadowradius/2,\shadowradius/2)$);
  27. \end{pgfonlayer}
  28. }
  29.  
  30. % create a shadow layer, so that we don't need to worry about overdrawing other things
  31. \pgfdeclarelayer{shadow}
  32. \pgfsetlayers{shadow,main}
  33.  
  34.  
  35. \newcommand\shadowimage[2][]{%
  36. \begin{tikzpicture}
  37. \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[#1]{#2}};
  38. \drawshadow{image}
  39. \end{tikzpicture}}
  40. % end of the preamble stuff
  41.  
  42. % this is what you put in your document - replace {image} with your image file name e.g. {my picture}
  43. \begin{document}
  44.  
  45. \shadowimage[width=5cm]{image}\par\bigskip
  46.  
  47. \shadowimage[width=8cm]{image}
  48.  
  49. \end{document}

Stef Pillaert
Posts: 33
Joined: Sat Oct 22, 2016 3:43 pm

Postby Stef Pillaert » Sat Jun 30, 2018 3:28 pm

This looks great! Can this also be used somehow to have the same effect on a box filled with text (minipage)?
Stef


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 6 guests