## 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.
Stefan Kottwitz
Posts: 9705
Joined: Mon Mar 10, 2008 9:44 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

Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm
Hmm, I'm ain't an expert on this. How do you suggest to define that macro ?

Stefan Kottwitz
Posts: 9705
Joined: Mon Mar 10, 2008 9:44 pm
Macros are an important strength of LaTeX. Define a macro once, and use it many times. For example, in the preamble:

\newcommand{\shadowpicture}[1]{%
\fboxrule=0pt
\fboxsep=0pt
\color{gray}
\normalcolor
}

Later, in the document:

\begin{figure}[H]
\centering
\caption{Another caption.}
\end{figure}

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

Stefan

Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm
Works perfectly well !

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

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

bloomy
Posts: 2
Joined: Thu Mar 20, 2014 12:44 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
\documentclass{article}
% put all this in the preamble
\usepackage{tikz}

% some parameters for customization

\colorlet{innercolor}{black!60}
\colorlet{outercolor}{gray!05}

% this draws a shadow under a rectangle node
\shade[outercolor,inner color=innercolor,outer color=outercolor] ($(#1.south west)+(\shadowshift)+(\shadowradius/2,\shadowradius/2)$) circle (\shadowradius);
\shade[outercolor,inner color=innercolor,outer color=outercolor] ($(#1.north west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$) circle (\shadowradius);
\shade[outercolor,inner color=innercolor,outer color=outercolor] ($(#1.south east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$) circle (\shadowradius);
\shade[outercolor,inner color=innercolor,outer color=outercolor] ($(#1.north east)+(\shadowshift)+(-\shadowradius/2,-\shadowradius/2)$) circle (\shadowradius);
\shade[top color=innercolor,bottom color=outercolor] ($(#1.south west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$) rectangle ($(#1.south east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$);
\shade[left color=innercolor,right color=outercolor] ($(#1.south east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$) rectangle ($(#1.north east)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$);
\shade[bottom color=innercolor,top color=outercolor] ($(#1.north west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$) rectangle ($(#1.north east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$);
\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)$);
\filldraw ($(#1.south west)+(\shadowshift)+(\shadowradius/2,\shadowradius/2)$) rectangle ($(#1.north east)+(\shadowshift)-(\shadowradius/2,\shadowradius/2)$);
\end{pgfonlayer}
}

% create a shadow layer, so that we don't need to worry about overdrawing other things

\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[#1]{#2}};
\end{tikzpicture}}
%  end of the preamble stuff

% this is what you put in your document  - replace {image} with your image file name e.g. {my picture}
\begin{document}

\end{document}

Stef Pillaert
Posts: 43
Joined: Sat Oct 22, 2016 3:43 pm
This looks great! Can this also be used somehow to have the same effect on a box filled with text (minipage)?
Stef