# tikz: Better raised text effect

If you look carefully at the raised text in this image, you can see that it has two drop shadows: as well as the black one to the southeast of the text, there is a white one to the northwest. I know how to insert one drop shadow in tikz using e.g.

drop shadow={shadow xshift=-0.5mm,shadow yshift=-0.5mm,black}


Is there any easy way to add two shadows of the kind specified? (NB. Being able to specify the 'light direction' via shadow xshift,shadow yshift is very useful.)

With key preaction another shadow can be inserted, e.g.:

\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\fill[lightgray] (0,0) rectangle (2,2);
\node[
fill=darkgray,
preaction={
fill=white,
opacity=1,
},
},
fill=black,
opacity=1,
},
] at (1,1) {\rule{8mm}{0mm}\rule{0mm}{8mm}};
\end{tikzpicture}
\end{document}


This can be further simplified. drop shadow uses general shadow, which is already implemented via preaction. Thus the preaction part can be dropped:

  \node[
fill=darkgray,
fill=white,
opacity=1,
},
fill=black,
opacity=1,
},
] at (1,1) {\rule{8mm}{0mm}\rule{0mm}{8mm}};


Also a style can be defined to simplify the use case, e.g.:

\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}

\pgfkeysdefnargs{/my/get value}{2}{%
\pgfkeysgetvalue{#1}{#2}%
}
\tikzset{
fill=white,
opacity=1,
#1,%
},
fill=black,
opacity=1,
#1%
}
}
}

\begin{document}
\begin{tikzpicture}
\fill[lightgray] (0,0) rectangle (2,2);
\node[
fill=darkgray,
fill=white,
opacity=1,
},
fill=black,
opacity=1,
},
] at (1,1) {\rule{8mm}{0mm}\rule{0mm}{8mm}};
\end{tikzpicture}
\begin{tikzpicture}
\fill[lightgray] (0,0) rectangle (2,2);
\node[
fill=darkgray,
},
] at (1,1) {\rule{8mm}{0mm}\rule{0mm}{8mm}};
\end{tikzpicture}

\end{document}


The following version without package tikz sets the text three times, first in color white, moved to the left and raised, then in color black to the right and below, finally the the text:

\documentclass{article}
\usepackage{xcolor}

\newcommand*{\RaisedText}[1]{%
\begingroup
\leavevmode
\rlap{\kern-.1pt\raise.1pt\hbox{\color{white}#1}}%
\rlap{\kern.1pt\raise-.1pt\hbox{\color{black}#1}}%
\hbox{#1}%
\endgroup
}

\begin{document}
\colorbox{lightgray}{%
\color{darkgray}\RaisedText{Raised Text}%
}
\end{document}


A variant with package pdfrender:

\documentclass{article}
\usepackage{xcolor}
\usepackage{pdfrender}

\newcommand*{\RaisedText}[1]{%
\begingroup
\leavevmode
\rlap{\kern-.1pt\raise.1pt\hbox{%
\pdfrender{
TextRenderingMode=Stroke,
LineWidth=.2pt,
StrokeColor=white,
}#1%
}}%
\rlap{\kern.1pt\raise-.1pt\hbox{%
\pdfrender{
TextRenderingMode=Stroke,
LineWidth=.2pt,
StrokeColor=black,
}#1%
}}%
\rlap{%
\pdfrender{
TextRenderingMode=Stroke,
LineWidth=.2pt,
}#1%
}%
\hbox{#1}%
\endgroup
}

\begin{document}
\colorbox{lightgray}{%
\color{darkgray}\RaisedText{Raised Text}%
}
\end{document}


• Unfortunately I'm actually trying to use the effect on more complex tikz elements, not on text... sorry I didn't make that clear. – Mohan Jun 14 '14 at 23:16
• @Tarass: The preaction answer is both perfect and general. – Mohan Jun 15 '14 at 12:26
• @Mohan I do not see how the preaction answer could be changed to fit raised text - could you elaborate? – Paulo Ney Aug 5 '16 at 17:49