如何给 tikz 线添加阴影?

如何给 tikz 线添加阴影?

我有下面的tikz图片。

\documentclass{standalone}

\usepackage{tikz}
\usepackage{xcolor}

\begin{document}

\begin{tikzpicture}[
  arr/.style={->,   blue, very thick},
  lbl/.style={draw, blue, very thick},
  ]
  \draw[fill=red, very thin] (-1,-1) rectangle (1,1);

  \draw[arr] (-2,0) .. controls (-.75,-.25)  and ( -.25,.75) .. (.5,0); % ARROW
  \node[lbl, anchor=north west] at (.5,0) {};                           % RECTANGLE
\end{tikzpicture}

\end{document}

tikz 箭头

如何在蓝色矩形下添加阴影?

如何添加跟随蓝色箭头的阴影?

答案1

要向节点添加阴影,您可以使用shadows库及其drop shadow选项。

要给路径添加阴影,您可以shadowed使用transform canvas选项定义样式。

在此处输入图片描述

\documentclass[tikz]{standalone}
\usetikzlibrary{shadows}
\begin{document}
\begin{tikzpicture}
  \tikzset{
    arr/.style={->,blue,very thick},
    lbl/.style={draw,blue,very thick},
    shadowed/.style={preaction={transform canvas={shift={(2pt,-1pt)}},draw=gray,very thick}},
  }
  \draw[fill=yellow,very thin] (-1,-1) rectangle (1,1);
  \draw[arr,shadowed](-2,0) .. controls (-.75,-1) and ( -.25,1) .. (.5,0)
  node[lbl,anchor=north west,fill=yellow,drop shadow] {};
\end{tikzpicture}
\end{document}

答案2

你可以使用 的一个小翻译版本来模拟它(0.02,-0.02)。或者你可以定义一些命令来使设置更容易。

\documentclass{standalone}

\usepackage{tikz}
\usepackage{xcolor}

\begin{document}

\begin{tikzpicture}[
  arr/.style={->,   blue, very thick},
  lbl/.style={draw, blue, very thick},
  ]
  \draw[fill=red, very thin] (-1,-1) rectangle (1,1);
  \draw[xshift=.02,yshift=-0.02,black,very thick,->] (-1.98,-.02) .. controls (-.75,-.25)  and ( -.25,.75) .. (.52,-0.02); % ARROW SHADOW
  \draw[arr] (-2,0) .. controls (-.75,-.25)  and ( -.25,.75) .. (.5,0); % ARROW
  \node[lbl, anchor=north west,black] at (.52,-0.02) {}; %RECT SHADOW
  \node[lbl, anchor=north west] at (.5,0) {}             % RECTANGLE

\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容