2

I need to achieve such a soft drop shadow using only tikz! without contour, pgf-blur or simmilar. enter image description here

I was searching for the solution, but was not managed to find one with tikz.

However, I have noticed a tikz's library called shadows. I tried to implement that, but I'm getting a rectangular shaddow instead of text-like.

\documentclass[12pt]{article}

\usepackage{tikz}
\usetikzlibrary{shadows.blur}

\begin{document}

\begin{tikzpicture}
\node[preaction={blur shadow={shadow xshift=-.5mm,shadow yshift=.5mm}}] at (1,1) {Test};
\end{tikzpicture}

\end{document}

enter image description here

Probably, if I am bale to blur the text using tikz, it will for for me, I will just put one behind and it is done.

BambOo
  • 8,801
  • 2
  • 20
  • 47
antshar
  • 4,238
  • 9
  • 30

1 Answers1

9

Here is a hundred percent handcrafted pure-TikZ solution (no libraries no nothing).

It does pretty much the same thing as pgf-blur or contour I guess.

\documentclass[tikz]{standalone}

\pgfmathsetmacro{\randamp}{0.005}
\pgfmathtruncatemacro{\totshadow}{30}

\begin{document}

\begin{tikzpicture}
\begin{scope}[xshift=0.2em,yshift=-0.2ex]
   \path[opacity=0.01] foreach \nshadow [evaluate=\nshadow as \angshadow using \nshadow/\totshadow*360] in {1,...,\totshadow}{
        node at (\angshadow:\randamp) {Text}
    };
\end{scope}
\node[] at (0,0) {Text};
\end{tikzpicture}

\end{document}

EDIT : Here is something that aims at begin a bit closer to the request in the comments. Without the definition of the parameters "spread" and others, I can't know for sure though.

\documentclass[tikz]{standalone}

\pgfmathsetmacro{\shadowangle}{132}
\newlength{\shadowdistance}
\pgfmathsetlength{\shadowdistance}{0.2ex}
\pgfmathsetmacro{\shadowopacity}{0.9}
\pgfmathsetmacro{\shadowspread}{0.002}
\pgfmathsetmacro{\shadowsize}{0}
\pgfmathtruncatemacro{\totshadow}{100}

\begin{document}
\begin{tikzpicture}
    \path[opacity={\shadowopacity/\totshadow},shift={({\shadowangle-180}:\shadowdistance)},scale={1+\shadowsize}]
    foreach \nshadow [evaluate=\nshadow as \angshadow using \nshadow/\totshadow*360] in {1,...,\totshadow}{
        node at (\angshadow:\shadowspread) {Text}
        };
    \node[] at (0,0) {Text};
\end{tikzpicture}


\end{document}

enter image description here

BambOo
  • 8,801
  • 2
  • 20
  • 47
  • Brilliant! Thank you so much! – antshar May 24 '20 at 15:04
  • I am wondering whether it is possible to manage "spread" and "size" like so: https://imgur.com/yZPK60w with your method? – antshar May 24 '20 at 15:08
  • Basically you can have the same result with the current parameters, play a bit with randamp and totshadow and you will see – BambOo May 24 '20 at 15:10
  • @antshar I tried something a bit closer to what you showed in your comment. If you have resources about these settings the maths should not be that hard. – BambOo May 24 '20 at 17:55
  • Amazing! Thank you! – antshar May 25 '20 at 10:32
  • @antshar I saw some stuff about CSS or illustrator settings, which I tried to replicate as best as possible, but they never really tell how it is working in the background. Let me know if you find additional informations on their settings. – BambOo May 25 '20 at 10:55